PDA

View Full Version : QSystemTrayIcon +Qt 5.5 Ubuntu 14.04



e.n.
4th October 2015, 00:17
QSystemTrayIcon don`t emit signal "activated" when the icon clicked. I read that in the previous version it was a bug, but it should have been corrected.

I have Qt 5.5.0 + Ubuntu 14.04 (Gnome).

tray.h



class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void showMsg(QSystemTrayIcon::ActivationReason reason);

private:
QSystemTrayIcon *trIcon;
QAction *actClose;
QMenu *menu;

};



tray.cpp



...
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{

actClose = new QAction("Close", this);
...

this->menuBar()->setNativeMenuBar(false);
menu = menuBar()->addMenu(tr("&File"));
menu->addAction(actClose);

trIcon = new QSystemTrayIcon(this);
trIcon->setIcon(QIcon(":/main_icon.png"));
trIcon->setContextMenu(menu);


connect(trIcon, &QSystemTrayIcon::activated, this, &MainWindow::showMsg);

trIcon->show();


}

MainWindow::~MainWindow()
{
}

void MainWindow::showMsg(QSystemTrayIcon::ActivationRea son reason)
{
qDebug() << "show message";

}


Anybody have any idea? Thank)

Jayes
9th November 2015, 10:42
shouldn't that like more like this? :

QObject::connect(mytrayicon, SIGNAL(activated(QSystemTrayIcon::ActivationReason )), this, SLOT(on_activated(QSystemTrayIcon::ActivationReaso n)));

anda_skoa
9th November 2015, 12:28
shouldn't that like more like this? :

QObject::connect(mytrayicon, SIGNAL(activated(QSystemTrayIcon::ActivationReason )), this, SLOT(on_activated(QSystemTrayIcon::ActivationReaso n)));

That would work as well.
Your syntax is the traditional macro using connect(), the thread started used the pointer-to-member-function syntax (an addition in Qt5).

Cheers,
_