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

DBus QSystemTrayIcon does not work or causes crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.5.1, 5.6.1
    • 5.5.0
    • QPA: X11/XCB
    • None
    • Qt 5.5.0 gcc 64 from installer, KDE 4.13.3-0ubuntu0.2

    Description

      When the DBus / StatusNotifier based system tray icon is used with Qt 5.5.0, rebuilding the tray menu leads to a bad state. In this state, the old menu continues to be shown, but clicking on actions either has no effect or causes a crash.

      Test code:

      #include <QApplication>
      #include <QSystemTrayIcon>
      #include <QMenu>
      #include <QDebug>
      #include <QTimer>
      
      class Handler : public QObject
      {
          Q_OBJECT
      
      public slots:
          void trigger()
          {
              qDebug() << "Triggered";
          }
      
          void setupMenu()
          {
              menu.clear();
      
              QAction *action1 = menu.addAction("Debug output: Triggered");
              connect(action1, SIGNAL(triggered()), SLOT(trigger()));
      
              QAction *action2 = menu.addAction("Re-setup menu");
              connect(action2, SIGNAL(triggered()), SLOT(setupMenu()));
      
              menu.addAction(QString::number(rand()));
          }
      
      public:
          QMenu menu;
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QSystemTrayIcon tray;
          Handler h;
      
          tray.setContextMenu(&h.menu);
          tray.show();
          h.setupMenu();
      
          return a.exec();
      }
      
      #include "main.moc"
      

      After clicking Re-setup menu the old menu continues to be shown and actions no longer work.

      ogoffart suggested this may be related to menuItemsById not being cleaned up in http://code.woboq.org/qt5/qtbase/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp.html#menuItemsByID

      See also https://github.com/owncloud/client/issues/3656 and possibly QTBUG-46293.

      Attachments

        Issue Links

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

          Activity

            People

              srutledg Shawn Rutledge
              ckamm Christian Kamm
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes