Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Minimal QSystemTrayIcon example in Ubuntu 12.04
QtWS25 Last Chance

Minimal QSystemTrayIcon example in Ubuntu 12.04

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsystemtrayiconqt 5.4.2ubuntu 12.04
7 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luipugs
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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".

      L 1 Reply Last reply
      1
      • ? A Former User

        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".

        L Offline
        L Offline
        luipugs
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          This is what I mean: http://www.howtogeek.com/68119/how-to-bring-app-icons-back-into-unitys-system-tray/ Don't know if it is still true.

          L 1 Reply Last reply
          0
          • ? A Former User

            This is what I mean: http://www.howtogeek.com/68119/how-to-bring-app-icons-back-into-unitys-system-tray/ Don't know if it is still true.

            L Offline
            L Offline
            luipugs
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luipugs
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luipugs
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved