Qt QSystemTrayIcon::setIcon or QIcon() not working

2019-09-11 06:36发布

using qt 5.5 on linux (ubuntu), I have very simple code (in main.cpp):

//QCoreApplication a(argc, argv);
QApplication a(argc, argv);

// Test if QLabel can show the icon
QLabel *label = new QLabel();
label->setPixmap(QPixmap("icon16.png"));
label->show();

// Do the same for QSystemTray
QSystemTrayIcon i;
QIcon icon(QPixmap("icon16.png"));
i.setIcon(icon);
i.show();
//    i.showMessage("hey dude!", "this is my message");
qDebug("done\n\n");

So here I am trying to dislpay a system tray icon... which works, but the icon is a red circle with a cross through it (showing that no icon is available). The commented out "showMessage()" function also works fine.

I know that the icon itself can be loaded and displayed by qt because it works for the QLabel.

The problem is that the QSystemTrayIcon is not displayed.

I have been through this post Another Persons Issue With QSystemTrayIcon, but he has a different issue to me in the end.

I can't figure out what the problem is here :(

edit

There are these links that suggest this is broke:

标签: c++ linux qt
0条回答
登录 后发表回答