Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-124237

crash when hide and destroy modal QWidget with another modal QWidget behind

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1: Critical P1: Critical
    • None
    • 6.6.2, 6.6.3, 6.7.0
    • QPA: X11/XCB
    • None
    • Linux/X11

      https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40886#note_1854394876

      reproduce steps:

      1. create cppcrash.cpp:

      cppcrash.cpp
      #include <QApplication>
      #include <QWidget>
      #include <QMouseEvent>
      
      struct MyWidget3:QWidget{
      	using QWidget::QWidget;//inherit constructors
      	void mousePressEvent(QMouseEvent *event){
      		this->hide();
      		this->deleteLater();//`delete this;` or `this->destroy();` also crash
      	}
      };
      
      struct MyWidget2:QWidget{
      	using QWidget::QWidget;//inherit constructors
      	void mousePressEvent(QMouseEvent *event){
      		MyWidget3 *w3=new MyWidget3(nullptr,Qt::Window);
      		w3->setAttribute(Qt::WA_DeleteOnClose);//delete this line if you want memory leak
      		w3->setWindowTitle("click me (MyWidget3)");
      		w3->setWindowModality(Qt::ApplicationModal);
      		w3->show();
      	}
      };
      
      struct MyWidget1:QWidget{
      	using QWidget::QWidget;//inherit constructors
      	void mousePressEvent(QMouseEvent *event){
      		MyWidget2 *w2=new MyWidget2(nullptr,Qt::Window);
      		w2->setAttribute(Qt::WA_DeleteOnClose);//delete this line if you want memory leak
      		w2->setWindowTitle("click me (MyWidget2)");
      		w2->setWindowModality(Qt::ApplicationModal);
      		w2->show();
      	}
      };
      
      int main(int argc,char **argv){
      	QApplication a(argc,argv);
      	MyWidget1 w1(nullptr,Qt::Window);
      	w1.setWindowTitle("click me (MyWidget1)");
      	w1.show();
      	a.exec();
      }
      

      2. run:

      g++ \
      cppcrash.cpp \
      -o cppcrash \
      -O0 \
      -ggdb \
      -I/usr/include/x86_64-linux-gnu/qt6 \
      -I/usr/include/x86_64-linux-gnu/qt6/QtWidgets \
      -I/usr/include/x86_64-linux-gnu/qt6/QtGui \
      -I/usr/include/x86_64-linux-gnu/qt6/QtCore \
      -lQt6Core \
      -lQt6Gui \
      -lQt6Widgets
      

      3. run:

      ./cppcrash
      

      4. click inside window named "click me (MyWidget1)"

      5. click inside window named "click me (MyWidget2)"

      6. click inside window named "click me (MyWidget3)"

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            liaqi Liang Qi
            bzzzz BZZZZ DZZZZ
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes