В Qt 5.4 происходит сбой при уничтожении объекта QQuickView. Авария не видна, если setQuitOnLastWindowClosed
не установлено, по умолчанию true
, QDOC.
#include <QGuiApplication>
#include <QQuickView>
#include <QObject>
#include <QDebug>
class VDestroyer : public QObject
{
Q_OBJECT
public:
explicit VDestroyer(QQuickView *view, QObject *parent = 0) :
QObject(parent), m_view(view)
{
// destroy m_view in 5 secs
timerId = startTimer(5 * 1000);
}
protected:
void timerEvent(QTimerEvent * event)
{
if (event->timerId() == timerId) {
m_view->deleteLater();
}
}
private :
QQuickView *m_view;
int timerId;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
QQuickView *view = new QQuickView;
view->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
view->show();
VDestroyer *vDestroyer = new VDestroyer(view);
int rc = app.exec();
qDebug() << "exiting from application!!";
delete vDestroyer;
return rc;
}
#include "main.moc"
Доступен полный отчет о сбое Вот.
(gdb) bt
#0 0x00007f204bc47cf4 in QBasicAtomicOps<8>::testAndSetRelaxed<QMutexData*> (
_q_value=@0x48: <error reading variable>, expectedValue=0x0, newValue=0x1,
currentValue=0x7ffe453fa360)
at ../../include/QtCore/../../src/corelib/arch/qatomic_x86.h:259
#1 0x00007f204bc47af0 in QGenericAtomicOps<QBasicAtomicOps<8> >::testAndSetAcquire<QMutexData*, QMutexData*> (currentValue=0x7ffe453fa360, newValue=0x1, expectedValue=0x0,
_q_value=@0x48: <error reading variable>)
at ../../include/QtCore/../../src/corelib/thread/qgenericatomic.h:166
#2 QBasicAtomicPointer<QMutexData>::testAndSetAcquire (this=0x48, expectedValue=0x0,
newValue=0x1, currentValue=@0x7ffe453fa360: 0x7ffe453fa390)
at ../../include/QtCore/../../src/corelib/thread/qbasicatomic.h:270
#3 0x00007f204bc477ab in QBasicMutex::fastTryLock (this=0x48,
current=@0x7ffe453fa360: 0x7ffe453fa390) at thread/qmutex.h:82
#4 0x00007f204bc46fa4 in QMutex::lock (this=0x48) at thread/qmutex.cpp:212
#5 0x00007f204be8efd9 in QCoreApplication::postEvent (receiver=0x12fd0e0, event=0x1547610,
priority=0) at kernel/qcoreapplication.cpp:1305
#6 0x00007f204bed0fe2 in QObject::deleteLater (this=0x12fd0e0) at kernel/qobject.cpp:2125
#7 0x0000000000401c24 in qCleanupResources_qml () at qrc_qml.cpp:81
#8 0x00007f204becf1c7 in QObject::event (this=0x1518740, e=0x7ffe453fa760)
at kernel/qobject.cpp:1226
#9 0x00007f204be8ea82 in QCoreApplicationPrivate::notify_helper (this=0x12bfec0,
receiver=0x1518740, event=0x7ffe453fa760) at kernel/qcoreapplication.cpp:1052
#10 0x00007f204be8e709 in QCoreApplication::notify (this=0x7ffe453fab00, receiver=0x1518740,
event=0x7ffe453fa760) at kernel/qcoreapplication.cpp:997
#11 0x00007f204c27bb52 in QGuiApplication::notify (this=0x7ffe453fab00, object=0x1518740,
event=0x7ffe453fa760) at kernel/qguiapplication.cpp:1528
проект
https://github.com/shrkamat/QlmResourceCleanup.git
Разрушение QQuickView с запуском цикла событий приложения должно быть разрешено, похоже на ошибку Qt.
QTimer повторяется по умолчанию, http://doc.qt.io/qt-5/qtimer.html#singleShot-prop это приведет к удалению уже уничтоженного объекта.
Других решений пока нет …