0

I have a Qt application with a system tray icon and a menu that shows up when right-clicking the icon. For some reason, the menu items work fine in debug mode but not in release mode.

QAction* closeAction = new QAction("Close", this);

QMenu* trayIconMenu = new QMenu(this);
trayIconMenu->addAction(closeAction);

QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
QIcon trayIconIcon("Application.png");
trayIcon->setIcon(trayIconIcon);
trayIcon->show();

QObject::connect(closeAction, SIGNAL(triggered()), this, SLOT(trayIconCloseAction_triggered()));


void MainWindow::trayIconCloseAction_triggered() {
  MessageBoxes::info("Close item clicked");
}

When I right-click on the icon, the menu shows up but clicking on "Close" does nothing - trayIconCloseAction_triggered() is not called at all. It does this only in release mode. Does anybody know what could be the reason?

I am using Windows 7 and Qt Creator, building with an MSV-2010 static build of Qt.

Edit: The icon does not react to click events ("activated" signals) either. Again in debug mode it works, but not release.

Cfun
  • 8,442
  • 4
  • 30
  • 62
laurent
  • 88,262
  • 77
  • 290
  • 428
  • try to rebuild your project: 1. erase "release" and "debug" folders in your build directory, 2. use "clean all" action from "build" menu in Qt creator, 3. switch to release mode and then use "rebuild all" action, 4. press Ctrl+R and check needed functionality – Johnny Mar 07 '11 at 06:51
  • Added: 3. before "rebuild all" also use "Run qmake" action – Johnny Mar 07 '11 at 07:00
  • 1
    Yes that did it, thanks a lot! Feel free to add your comments as an answer and I'll mark it as accepted. – laurent Mar 07 '11 at 09:17

1 Answers1

1

In situations like this there is a general recommendation:

  1. Erase "release" and "debug" folders in your build directory,
  2. Use "clean all" action from "build" menu in Qt creator,
  3. Switch to release mode and then use "Run qmake", "rebuild all" actions,
  4. Press Ctrl+R and check needed functionality.
Johnny
  • 1,966
  • 17
  • 24