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

Cocoa: Adding a ApplicationSpecificRole Action into the main menu after cleanup results in duplicate items

XMLWordPrintable

      To see the issue in the following code, build and click on the test2 menu item.

      note that moving the delete of the mAppSpec action up to the top of the
      create() method will workaround the issue in 4.7, but causes a crash in 4.6

      //main.cpp
      #include <QApplication>
      #include <QMainWindow>
      #include <QMenuBar>
      #include <QAction>
      
      class test: public QMainWindow
      {
          Q_OBJECT;
      
      public:
          test()
            :QMainWindow()
          {
              tt = new QMenu(this);
              mTest = new QAction(this) ;
              mAppSpec = new QAction(this) ;
              create();
          }
      
      signals:
          void test1();
      
      public slots:
          void create()
          {
      //        delete mAppSpec;
              delete tt;
      
              QMenuBar *pMenuBar = menuBar();
              tt = new QMenu(this);
              tt->setTitle("Test");
              delete mTest;
              mTest = new QAction(this);
              mTest->setText("test2");
              connect (mTest, SIGNAL(triggered()),
                       this, SLOT(onClicked()));
      
              tt->addAction(mTest);
      
              delete mAppSpec;
              mAppSpec = new QAction(this);
              mAppSpec->setText("App Spec");
              mAppSpec->setMenuRole(QAction::ApplicationSpecificRole);
              connect (mAppSpec, SIGNAL(triggered()),
                       this, SLOT(onAppSpec()));
      
              tt->addAction(mAppSpec);
      
              pMenuBar->addMenu(tt);
          }
          void onClicked()
          {
              create();
          }
      
          void onAppSpec()
          {
              qDebug("app spec");
          }
      
      private:
          QMenu *tt;
          QAction *mTest;
          QAction *mAppSpec;
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app (argc, argv);
          test *mw = new test;
          mw->show();
          return app.exec();
      }
      
      #include "main.moc"
      
      

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

            richard Richard Moe Gustavsen
            dettman Dean Dettman (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes