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 in 4.8 - how to delete this thing?
QtWS25 Last Chance

QSystemTrayIcon in 4.8 - how to delete this thing?

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

    As the title says, what is this thing and how do I handle it?

    It's a QObject and asks for a QObject as it's parent. But at the same time it has child objects that are QWidgets.

    With most QObjects, you can either let the parent delete it when the parent is deleted, or you can delete it yourself. But QSystemTrayIcon doesn't seem to work this way - I've tried making it the child of an arbitrary QObject and then letting it's parent delete it - when I do this, a lingering event gets sent to the QSystemTrayIcon that's been parent-deleted. On OSX this segfaults because it ends up sending an obj message to an invalid object.

    This might be because the QMainWindow is going away at the same time in my application.

    If I have to delete it explicitly after un-childing it, why? And if that's the case, it sounds like this is timing-dependent or something.

    If QSystemTrayIcon really just wants a QWidget as its parent, why isn't its constructor written that way?

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

      Hi,

      Have a look at the "System Tray Icon Example"

      You'l see how to use it

      Hope it helps

      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
      • T Offline
        T Offline
        tedmiddleton
        wrote on last edited by
        #3

        Ok - looks good. So it must be parented to a QWidget, it's constructor signature notwithstanding?

        If I wanted to delete one early, before it's parent is deleted, how do I do that? I can't set Qt::WA_DeleteOnClose. Do I just delete it directly? Do I use deleteLater(), in spite of the fact that multiple threads aren't involved?

        [quote author="SGaist" date="1399622416"]Hi,

        Have a look at the "System Tray Icon Example"

        You'l see how to use it

        Hope it helps[/quote]

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

          No it must not, QWidget is a QObject derived class.

          deleteLater is generally the way to go, the event loop will delete it at the best moment.

          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
          • T Offline
            T Offline
            tedmiddleton
            wrote on last edited by
            #5

            Sorry - I don't understand. Can QSystemTrayIcon be a child of any old QObject (as the ctor signature would suggest), or is it required to be a child of a QWidget (as the example code and my own segfault experience seems to suggest)?

            [quote author="SGaist" date="1399668486"]No it must not, QWidget is a QObject derived class.

            deleteLater is generally the way to go, the event loop will delete it at the best moment.[/quote]

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

              QObject, if you have a crash, then there is something spurious. Can you share the code where you have that crash happening ?

              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