Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QtWinmigrate and __fastfail on deleting Qt Quick models
antdm last edited by antdm
I'm using qtwinmigrate with Qt 5.12.5 to display Qt Quick controls in a Win32 app.
More specifically, I have a C interface to a dll where I host a QQmlEngine instance that renders things through QQuickWidget which I show in the client application with help of QWinWidget (which is part of the qtwinmigrate framework).
If I don't delete model objects then there is memory leaking each time when I hide then show the widget even if I don't recreate model objects but reusing old objects from a pool instead. I suspect old QML objects to be leaking.
Since deleteLater() doesn't work because of absence of main Qt thread executing QApplication's event loop I've googled next way to delete model objects:
QApplication::postEvent(m_Model, new QDeferredDeleteEvent()); Application::sendPostedEvents(0, QEvent::DeferredDelete);
It seemed to work well, everything was working fine and no memory was leaking. Unfortunately, I've recently discovered that sometimes it results in calls to __fastfail with next message:
Object destroyed while one of its QML signal handlers is in progress. Most likely the object was deleted synchronously (use QObject::deleteLater() instead), or the application is running a nested event loop. This behavior is NOT supported!
Calling disconnect() on these objects prior to deleting doesn't help.
An attempt to create a QThread in the dll, move QApplication instance to this thread and run its event loop through calling exec() on it, then call deleteLater() on model objects normally failed as well. Model objects were not being deleted in this case. I might have done something wrong though.
Do you have any suggestions what can I do with this problem?
I've tried to reimplement the "in-dll QThread" approach once again since I definitely did it wrong for the first time. Now everything is created and lives in that thread but I can't display the control:
- I see next warning from Qt:
WARNING: QApplication was not created in the main() thread.
- QWinWidget's constructor hangs on next call
SetWindowLong((HWND)winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
And since I'm using Qt::BlockingQueuedConnection for synchronization with the main thread it hangs as well.