PDA

View Full Version : Tray menu doesn't work on Mac



skruffynerherder
11th March 2013, 15:54
I've made an application that makes use of system tray. It works fine in windows, but on Mac for some reason I am unable to open up its context menu when clicking it. Any suggestions?


void MainWindow::setTray() {
aboutA = new QAction("About", this);
settingsA = new QAction("Settings", this);
quitA = new QAction("Quit", this);

trayMenu->addAction(aboutA);
// trayMenu->addAction(settingsA);
trayMenu->addSeparator();
trayMenu->addAction(quitA);

connect(quitA, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(settingsA, SIGNAL(triggered()), this, SLOT(onSettings()));
connect(aboutA, SIGNAL(triggered()), this, SLOT(onAbout()));

tray->setIcon(*icon);
tray->setContextMenu(trayMenu);
tray->show();
}

Edit:

Oh and it seems to throw a warning upon compiling


QObject::connect: No such slot QSystemTrayIcon::emitActivated

I am unable to build and run the application though, but the context menu doesn't show :(

skruffynerherder
14th March 2013, 13:22
^^ sorry I meant I was able to build the application

Any ideas guys?

ChrisW67
14th March 2013, 21:53
The run time (not compile) warning "QObject::connect: No such slot QSystemTrayIcon::emitActivated " is exactly what it says. QSystemTrayIcon has no slot called emitActivated(). The code you show doesn't contain the failing connect() call. Does that exist in your code?

skruffynerherder
14th March 2013, 22:09
Yup, as mentioned it compiles without that error and runs/works brilliantly on windows

ChrisW67
14th March 2013, 23:03
I assume Qt 5 as the particular connect() to emitActivated() does not seem to exist in Qt 4.8. Try it with Qt 4.8 on the Mac and see if that works. I don't have a Mac to do this with.

If 4.8 works and 5.0 does not then raise it as a regression bug on the Qt bug tracker. Make sure you provide a small, self-contained program that demonstrates the problem, quote the warning exactly, and suggest that it may come from qtbase/widgets/util/qsystemtrayicon_qpa.cpp in QSystemTrayIconPrivate::install_sys(). I would hazard a guess that the failure to connect is causing the failure to open the menu.

Also try the snippet of code in QTBUG-26841