Minimal QSystemTrayIcon example in Ubuntu 12.04



  • Hello. 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.


  • Moderators

    Hi! Your Ubuntu uses the Unity desktop environment, right? IIRC Unity doesn't support "normal" tray icons but Canonical decides which applications are allowed to show a "tray icon".



  • @Wieland Hello. It worked in the machine where I compiled the source though, it only didn't work when I tried to deploy it to another machine.


  • Moderators



  • @Wieland Hmm, that worked but there should be another solution. For example Dropbox works without editing the systray whitelist.



  • I'll mark this as solved as editing the systray whitelist worked but I'll try looking for other solutions.



  • I tested in Ubuntu 14.04 up to 15.10 and the tray icon is still not shown. The systray whitelist is not available any more in those distributions though, and I'd rather not have to install packages that bring back the tray icon like https://launchpad.net/~gurqn/+archive/ubuntu/systray-trusty. I thought Qt 5.4.2 already supported app indicators?



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.