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

Memory leak caused by the default content menu of QMainWindow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.3, 5.0.0 Beta 1
    • 4.7.0, 5.0.0
    • Widgets: Main Window
    • None
    • Windows
    • Qt 4: 00bbab0dbfde79cfc6a3dc6060d7c87763f07482 , Qt 5: 7694599ef933b306d54116723adab0d5d8651ff5

    Description

      Right click on the menubar or docked widget several times, the default context menu will be shown one by one. When the new menu is shown, the old one does not destroyed. This will lead to memory leak.

      You can reproduce the problem with following code:

      • right click on the menubar or docked widget serveral times
      • then click the "dump object tree" button, you will see many menu objects in console window.
        #include <QtGui>
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        public:
            explicit MainWindow(QWidget *parent = 0);
        private slots:
            void onButtonClicked();
        };
        
        MainWindow::MainWindow(QWidget *parent)
        {
            addToolBar("ToolBar");
            addDockWidget(Qt::LeftDockWidgetArea, new QDockWidget("DockWidget"));
            QPushButton * btn = new QPushButton("dump object tree");
            setCentralWidget(btn);
            connect(btn, SIGNAL(clicked()), SLOT(onButtonClicked()));
        }
        
        void MainWindow::onButtonClicked()
        {
            dumpObjectTree();
        }
        
        #include "main.moc"
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            MainWindow w;
            w.show();
            return a.exec();
        }
        

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-19592
          # Subject Branch Project Status CR V

          Activity

            People

              dbzhang800 debao zhang
              dbzhang800 debao zhang
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes