segfault using PyQt6 version 6.10.1

Phil Thompson phil at riverbankcomputing.com
Fri Dec 26 14:58:26 GMT 2025


On 26/12/2025 13:29, Dmitry Shachnev wrote:
> Hi Phil!
> 
> On Fri, Dec 26, 2025 at 12:53:18PM +0000, Phil Thompson wrote:
>> I think this may be a bug in calibre (exposed by the change in 
>> v6.10.1).
>> calibre must have a Python reimplementation of 
>> createMimeDataFromSelection()
>> that returns a QMimeData object. It should (according to the Qt docs) 
>> set
>> the parent of that object to be the text editor. I suspect that it 
>> doesn't.
> 
> Indeed, Calibre does reimplement createMimeDataFromSelection() in two 
> places:
> 
> https://github.com/kovidgoyal/calibre/blob/e4dd51df48b8063c2fc9324a029ffdbf61b6d4ee/src/calibre/gui2/comments_editor.py#L1028
> 
> https://github.com/kovidgoyal/calibre/blob/e4dd51df48b8063c2fc9324a029ffdbf61b6d4ee/src/calibre/gui2/tweak_book/widgets.py#L1281
> 
> The first one gets the QMimeData from 
> super().createMimeDataFromSelection(),
> so it probably already has the correct parent.
> 
> The second one probably needs a ans.setParent(self) call. Can you 
> please
> confirm this?

This is all predicated on my interpretation of the Qt docs being correct 
- and I'm not sure it is. In the Qt source code I can't (after a very 
cursory look) find an example of a QMimeData instance with a parent. It 
also doesn't have a ctor that takes a parent parameter. The docs say 
"ownership...is passed to the caller". Looking at the 
createStandardContextMenu() source code the QMenu is definitely given a 
parent. Its docs say "ownership is transferred to the caller".

> This will work with both old (≤ 6.10.0) and new (6.10.1) PyQt, right?
> 
> Frescobaldi does the same, I left a comment there:
> 
> https://github.com/frescobaldi/frescobaldi/issues/2126#issuecomment-3692845244

I think the best thing to do at this point is to revert the v6.10.1 
change as it applies to createMimeDataFromSelection() and *not* make any 
application changes while I do some more digging.

I think there is a SIP bug in the support of virtual /Factory/ methods 
but it probably only means that the QMimeData Python object isn't 
garbage collected as soon as it could be.

Phil


More information about the PyQt mailing list