Closed galvinhoang closed 1 year ago
@galvinhoang: Hi!
I'm also have seen this problem in my tests, the solution (that i found), is prevent the application from exit before the widget gets destroyed.
Something like this:
Hold a QPointer
of the widget:
QPointer<QQuickWidget> m_quick_widget;
And delete that widget if it remains valid in close event:
void MainWindow::closeEvent(QCloseEvent *event)
{
if (m_quick_widget)
{
QEventLoop loop;
connect(m_quick_widget, &QQuickWidget::destroyed, &loop, &QEventLoop::quit);
QTimer::singleShot(0, m_quick_widget, &QQuickWidget::deleteLater);
loop.exec();
}
}
This will be present in the next version to be published this week (If everything is good).
Ah great to know! Thanks so much for the info!
@galvinhoang: This bug was solved on version 2.4. Note that the closeEvent
delete workaround is no more needed.
I am using your example ExampleMinimalWindow as a base.
The issue is reproducable by using this as mainwindow.cpp:
When closing the window, I get the following warning just before the program crashes:
So this is not catastrophic and I'll continue using the QQuickWidget because otherwise the program always works out fine. The average user may not care if the program crashes instead of closing properly (if he wanted the program to end anyway), but I thought, I report it as I didn't manage to really fix it and maybe you know what this is about.
When asking ChatGPT, it suggested to execute
bg->deleteLater();
when trying to close the program, however, the warning was always thrown before an implementation ofbg->deleteLater()
(for example in acloseEvent
override) was executed in the code.Qt source code (https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/rhi/qrhi.cpp at line 7506) indicates, that the application somehow manages to destroy the resources of a QRhi after the QRhi itself. (but didn't figure out yet, what exactly that means, I'll let you know if I find out anything interesting about it).