Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTest QMainWindow and deleteLater
Forum Updated to NodeBB v4.3 + New Features

QTest QMainWindow and deleteLater

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 434 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wasawi2
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • W wasawi2

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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?

      W 1 Reply Last reply
      0
      • JonBJ JonB

        @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?

        W Offline
        W Offline
        wasawi2
        wrote on last edited by
        #3

        Thank you @JonB,

        Yes I am using QML. do you think it should be related to not being able to destroy some QML object?

        JonBJ 1 Reply Last reply
        0
        • W wasawi2

          Thank you @JonB,

          Yes I am using QML. do you think it should be related to not being able to destroy some QML object?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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.

          W 1 Reply Last reply
          0
          • JonBJ JonB

            @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.

            W Offline
            W Offline
            wasawi2
            wrote on last edited by
            #5

            @JonB thank you so much. That was right.

            there was an object that was calling deleteLater in different places and that caused a crash.

            It was definitelly on my side.

            Thanks!

            1 Reply Last reply
            0
            • SGaistS SGaist has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved