ubuntu-12.04qt5.4

Minimal QSystemTrayIcon example in Ubuntu 12.04


I am studying how to build and deploy a Qt application with Ubuntu 12.04. I am working with Qt 5.4.2 which I downloaded here. I installed it in the default location ~/Qt5.4.2.

Currently I want to set a tray icon. My code is just the following:

#include <QApplication>
#include <QDebug>
#include <QIcon>
#include <QSystemTrayIcon>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QSystemTrayIcon *trayIcon = new QSystemTrayIcon();
    qDebug() << trayIcon->isSystemTrayAvailable();
    trayIcon->setIcon(QIcon("heart.png"));
    trayIcon->show();
    return app.exec();
}

heart.png is from PyQt5's QSystemTrayIcon example, I got it from here. I put it in the same directory as the source file.

I built the executable with the following commands.

~/Qt5.4.2/5.4/gcc_64/bin/qmake -config release
make

Running the created file shows the tray icon.

For deploying the app, I copied the following files into the same directory. I got them from ~/Qt5.4.2/5.4/gcc_64/lib:

libicudata.so.53
libicui18n.so.53
libicuuc.so.53
libQt5Core.so.5
libQt5DBus.so.5
libQt5Gui.so.5
libQt5Widgets.so.5

I also copied ~/Qt5.4.2/5.4/gcc_64/plugins/platforms/libqxcb.so and placed it under a directory named platforms.

I tested adding a qt.conf file, but it doesn't seem to have an effect. Its contents are

[Paths]
Prefix = .
Binaries = .

I copied over this whole directory to a VM running an Ubuntu 12.04 live CD. Before running the binary I exported LD_LIBRARY_PATH=. so that it will find the included Qt libraries.

Unfortunately the tray icon is not shown when the program is run in the VM. The qDebug statement shows that the system tray is available though.

Thanks in advance.


Solution

  • I solved this by editing the systray whitelist: http://www.howtogeek.com/68119/how-to-bring-app-icons-back-into-unitys-system-tray/