Important: Please read the Qt Code of Conduct -

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

  • 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[])
            QGuiApplication app(argc, argv);
            QQmlApplicationEngine engine;
            if (engine.rootObjects().isEmpty())
                return -1;
            return app.exec();
    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)

  • @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?

  • Lifetime Qt Champion

    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.

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

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

Log in to reply