QTest QMainWindow and deleteLater
-
Hello everyone,
I am testing a QMainWindow and I am unable to delete it. I have tried everything, but whatever i do, if i try to delete it the test will run into segmentation fault. My main window has several widgets in it and it destroys itself as follows:
CMainWindow::~CMainWindow ( ) { model_->BaseModel::StopRefresher( ); disconnect( model_, &CModel3D::OnLoggOut, this, &CMainWindow::OnLoggedOut ); disconnect( model_, &CModel3D::OnClose, this, &CMainWindow::OnExit ); if ( nullptr != model_ ) { model_->deleteLater( ); } if ( nullptr != lapView_ ) { lapView_->deleteLater( ); } if ( nullptr != stack_ ) { stack_->deleteLater( ); } if ( nullptr != view_ ) { view_->deleteLater( ); } }
here is my cleanup function, but as I say I haven't found a way to safely destroy the window.
void MainWindowTest::cleanup ( ) { // QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); // QCoreApplication::sendPostedEvents(0, -1); // QCoreApplication::processEvents(); // mainWindow_instance->close(); // mainWindow_instance->deleteLater( ); delete mainWindow_instance; // QCoreApplication::sendPostedEvents(0, -1); // QCoreApplication::processEvents(); QTest::qWait(250); }
As you can see i have tried to allow the event loop to process the deleteLater with things like QCoreApplication::sendPostedEvents, QCoreApplication::processEvents, QTest::qWait... but without luck.
it seems QT is trying to delete a shared pointer after finishing to run the destructor. Here is a gdb print out:
Thread 1 "" hit Breakpoint 4, CMainWindow::~CMainWindow (this=0x907f090, __in_chrg=<optimized out>) at /XXX/mainwindow.cpp:110 110 if ( nullptr != view_ ) (gdb) s 113 view_->deleteLater( ); (gdb) s 82 CMainWindow::~CMainWindow ( ) (gdb) s QSharedPointer<QQuickItemGrabResult>::~QSharedPointer (this=0x907f0f0, __in_chrg=<optimized out>) at ../XXX/include/QtCore/qsharedpointer_impl.h:316 316 ~QSharedPointer() { deref(); } (gdb) s QSharedPointer<QQuickItemGrabResult>::deref (this=0x907f0f0) at ../XXX/include/QtCore/qsharedpointer_impl.h:459 459 { deref(d); } (gdb) s QSharedPointer<QQuickItemGrabResult>::deref (dd=0x0) at ../XXX/include/QtCore/qsharedpointer_impl.h:462 462 if (!dd) return; (gdb) s 468 } (gdb) s Thread 1 "" received signal SIGSEGV, Segmentation fault. sem_close (sem=0x0) at /builds/workspace/QOS224-SDP/build_x86_64/lib/c/1b/sem_close.c:26 26 /builds/workspace/QOS224-SDP/build_x86_64/lib/c/1b/sem_close.c: No such file or directory.
Does anyone know what might be going on? it seems to me that it is crashing on QT side.. not in my side.
Thanks in advance!
w -
@wasawi2 said in QTest QMainWindow and deleteLater:
QSharedPointer<QQuickItemGrabResult>
If we are to believe this it would be to do with QtQuick/QML, which i would not have thought would be going on if you have a widgets application. You're not using any QtQuick/QML anywhere, are you?
-
@wasawi2
Well yes, in the sense that you can see what the output tells you, it's some shared pointer of a QQuickItemGrabResult, which you can look up.I know nothing about QML so I can't help further, but that is the object in question for this error.
-