Shariq
Shariq

Reputation: 25

QT/QML application crashes due to object ownership issue

I have a Qt/Qml application which uses a static Qt C++ library. The classes (models etc.) reside in the library whose objects are created in the application's main.cpp or QML files. Some of the classes are derived from QObject. I get segmentation faults when closing screens which have objects of these classes. I need to maintain the objects even after closing screens.

I have tried using QQmlEngine::setObjectOwnership(). I cannot use it in the constructor of these classes as QQmlEngine class is not available for a library project. So I set it in the application after the object has been created.

in Qml

here getDbpointObject() is a slot and returns an object of a class derived from QObject.

Then i pass the object to an internal class's function to set its ownership.

enter image description here

In some examples saw that its okay to set the ownership after the object has been created. Not sure if its correct or we necessarily need to do it in the constructor, for which i don't have a way?

Upvotes: 0

Views: 671

Answers (1)

Shariq
Shariq

Reputation: 25

I am not seeing any crash anymore. I am not sure if this was the cause but by mistake I had put QString return type from the setownership() call. After correcting it to void, I don't see the crash so seems things are working. Will monitor it further. Thanks for your help.

Upvotes: 0

Related Questions