Segmentation fault within some specific conditions

Phil Thompson phil at riverbankcomputing.com
Sat Mar 23 14:57:18 GMT 2024


On 06/03/2024 14:17, Erwan Mathieu wrote:
> Hello,
> 
> I'm running into a segmentation fault when using PyQt 6.6.0/6.6.1. I 
> could
> reproduce it with a very basic project, here is how to make it happen:
> 
> // File test.py
> from PyQt6.QtCore import QObject
> from PyQt6.QtGui import QGuiApplication
> from PyQt6.QtQml import QQmlApplicationEngine, qmlRegisterType
> 
> class MyModel(QObject):
>     def __init__(self, parent = None):
>         super().__init__(parent = parent)
>         print("I am alive")
>     def __del__(self):
>         print("I am dead ")
> 
> app = QGuiApplication([])
> qmlRegisterType(MyModel, "Test", 1, 0, "MyModel")
> engine = QQmlApplicationEngine()
> engine.load("./Main.qml")
> app.exec()
> 
> // File Main.qml
> import QtQuick
> import QtQuick.Controls
> 
> import Test 1.0
> 
> Window
> {
>     width: 640
>     height: 480
>     visible: true
>     title: qsTr("Hello World")
> 
>     Loader { id: loader; sourceComponent: superComponent; }
> 
>     Button
>     {
>         anchors.centerIn: parent
>         text: "Unload"
>         onClicked: loader.sourceComponent = null
>     }
> 
>     Component
>     {
>         id: superComponent
> 
>         Item
>         {
>             MyModel
>             {
>                 property var superProperty: "hello"
>             }
>         }
>     }
> }
> 
> Now start the test.py file, and click on the "Unload" button. The 
> Component
> instance is destroyed, which also destroys the MyModel instance. We can 
> see
> the print instructions that says so. Just after that, I get a 
> segmentation
> fault.
> 
> For some reason, this happens only when declaring a property on the 
> MyModel
> instance. If you comment the superProperty declaration, everything is 
> fine.
> 
> We were previously working with version 6.4.2, and this caused no 
> issue. I
> have it starting from 6.6.0 (but didn't try intermediate versions).
> 
> I also tried to make this example directly in C++, and I don't get the
> error, so I think this is related to PyQt.
> 
> If it is of any help, gdb gives me the following crash point:
> 0x00007ffff636abb0 in QMetaObject::methodOffset() const () from
> /..../lib/python3.10/site-packages/PyQt6/Qt6/lib/libQt6Core.so.6
> 
> Any idea of why this is happening, and if there is a workaround/fix ?
> 
> Kind regards,
> 
> Erwan MATHIEU

Should be fixed in the next snapshot (and v6.7.0). However, as is usual 
with QML, fixes in one area may break it in other areas. Fingers 
crossed.

Phil


More information about the PyQt mailing list