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. [SOLVED]QSystemTrayIcon for console applications
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QSystemTrayIcon for console applications

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hi all,

    Can I use QSystemTrayIcon for console applications?

    PS
    I tried to test it by using the following snippet but I got a runtime error:

    ---main.cpp

    @
    #include <QtCore/QCoreApplication>
    #include <QSystemTrayIcon>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSystemTrayIcon *iconTray = new QSystemTrayIcon(QIcon(":/pixmap/res/icon.png"));
    iconTray->show();
    
    return a.exec(&#41;;
    

    }
    @

    ---test.pro

    @
    QT += core

    QT += gui

    TARGET = TRAY-APP
    CONFIG += console
    CONFIG += app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    RESOURCES +=
    res.qrc
    @

    ---runtime error
    @
    QWidget: Cannot create a QWidget when no GUI is being used

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    @

    [EDIT: fixed code formatting, Volker]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You can build a console application in the sense that there is no main window or GUI or the like. But as you instantiate a GUI element - the QSystemTrayIcon - your application needs to initialize the graphics system. Therefore your need a QApplication instead of a QCoreApplication. If you change that, the code should work.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        Thanks a lot... it's working fine

        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