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. QSystemTrayIcon not available then run application with sudo on Ubuntu 18.04 LTS

QSystemTrayIcon not available then run application with sudo on Ubuntu 18.04 LTS

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 803 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.
  • T Offline
    T Offline
    Tolik
    wrote on last edited by
    #1

    If I run the application from sudo, the tray icon is not available. The problem is the same when using qml component SystemTrayIcon and when using the QSystemTrayIcon widget.

    sudo ./myapplication
    qml: SystemTrayIcon::available false
    
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
        int main(int argc, char *argv[])
        {
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
            QGuiApplication app(argc, argv);
    
            QQmlApplicationEngine engine;
            engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
            if (engine.rootObjects().isEmpty())
                return -1;
    
            return app.exec();
        }
    
    main.qml
    import QtQuick 2.12
    import QtQuick.Window 2.12
    import Qt.labs.platform 1.0
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Text {
            anchors.centerIn: parent
            text: "SystemTrayIcon::available: " + idSystemTrayIcon.available
        }
    
        SystemTrayIcon {
            id: idSystemTrayIcon
            visible: true
            Component.onCompleted: {
                console.log("SystemTrayIcon::available", available)
            }
        }
    }
    
    JonBJ 1 Reply Last reply
    0
    • T Tolik

      If I run the application from sudo, the tray icon is not available. The problem is the same when using qml component SystemTrayIcon and when using the QSystemTrayIcon widget.

      sudo ./myapplication
      qml: SystemTrayIcon::available false
      
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
          int main(int argc, char *argv[])
          {
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
              QGuiApplication app(argc, argv);
      
              QQmlApplicationEngine engine;
              engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              if (engine.rootObjects().isEmpty())
                  return -1;
      
              return app.exec();
          }
      
      main.qml
      import QtQuick 2.12
      import QtQuick.Window 2.12
      import Qt.labs.platform 1.0
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Text {
              anchors.centerIn: parent
              text: "SystemTrayIcon::available: " + idSystemTrayIcon.available
          }
      
          SystemTrayIcon {
              id: idSystemTrayIcon
              visible: true
              Component.onCompleted: {
                  console.log("SystemTrayIcon::available", available)
              }
          }
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Tolik
      Maybe that's just how it is on Ubuntu 18.04 (including: by default you're using GNOME instead of Unity now)? There are sometimes issues if an application runs as one user when the desktop is running as another?

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Are you having that issue with your distribution provided Qt ?

        Note that running GUI application as root may not work as by default the access to the Xorg server is disable for that user so you have to explicitly grant access. That might be part of the issue.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • T Offline
          T Offline
          Tolik
          wrote on last edited by
          #4

          Thank you for participating )
          Ubuntu 18.04 LTS gnome 3.28.2
          Build the program with Qt 5.12.1 (official build) and another program with 5.13 beta 2 (locally build).

          JonBJ 1 Reply Last reply
          0
          • T Tolik

            Thank you for participating )
            Ubuntu 18.04 LTS gnome 3.28.2
            Build the program with Qt 5.12.1 (official build) and another program with 5.13 beta 2 (locally build).

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Tolik
            As both I & @SGaist wrote, have you checked that you have the necessary settings/permissions for root to be allowed GUI applications fully in your logon session? This may not be a Qt code issue at all.

            1 Reply Last reply
            2

            • Login

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