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 accumulates

QSystemTrayIcon accumulates

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k 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.
  • kalmaK Offline
    kalmaK Offline
    kalma
    wrote on last edited by
    #1

    Hi

    Windows 7
    Qt 5.3.0 mingw

    I use the following code to show tray icon, but it stays there even after I close my application, they clear only when I hover over them, what wrong am I doing?

    @
    QSystemTrayIcon *icon = new QSystemTrayIcon(QIcon(":/icons/logo.png"));
    if(icon->isSystemTrayAvailable()){
    icon->show();
    icon->showMessage(tr("Help"), tr("Help text"), QSystemTrayIcon::Information, 2000);
    }
    @

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

      Hi,

      Since you did not give a parent to your QSystemTrayIcon, are you deleting it somewhere ?

      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
      0
      • kalmaK Offline
        kalmaK Offline
        kalma
        wrote on last edited by
        #3

        Thanks for the quick response SGaist!

        No, should I use (this) as parent?

        @
        QSystemTrayIcon *icon = new QSystemTrayIcon(QIcon(":/icons/logo.png"), this);
        @
        I am creating the icon in the main class of type (MainWindow).

        PS: I have posted the same by mistake in other forum (Cloud), I could not deleted it, sorry.

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

          Indeed you should. Without that you have a memory leak and icon will not be properly destroyed when your program ends

          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
          0
          • kalmaK Offline
            kalmaK Offline
            kalma
            wrote on last edited by
            #5

            Thanks, it worked nicely.

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

              You're welcome !

              Since it's now all working fine, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              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
              0

              • Login

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