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. How to pass QSystemTrayIcon control between QDialog and QmainWindow
Forum Updated to NodeBB v4.3 + New Features

How to pass QSystemTrayIcon control between QDialog and QmainWindow

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 5.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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #3

    is it ok to delete the QSystemTrayIcon when the QDialog is closed ( destroyed )
    and then i set new QSystemTrayIcon in the QMainWindow . works ok dont know if its the best way to do this

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #4

      Sure, that would work, but it would cause unneeded flicker in the system tray and generally waste resources. I would just make a single object controlling your QSystemTrayIcon, and create a single instance of that object with the QApplication as its parent. Much easier and cleaner.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #5

        you mean to make single tone ? in the main ? not related not to the QDialog and the QMainWindow?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #6

          "tone"? What is that?

          I mean to make a single class that is responsible for handling the icon. From where you instantiate that class, is not very relevant. It may be from the main, it may be from the QDialog, or it could even be from a subclassed QApplication. You could even considder making that class a singleton class, so it would instantiated by itself the first time it is accessed. The parent of that class would not be a class that is not around for the whole time you need the icon. That rules out both QDialog and QMainWindow. QApplication would be a logical candidate. In either case, note that the question of who instantiates the object is unrelated to the question of what object will be parent. QDialog can instantiate the object, and still make the qApp the parent.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #7

            ok thanks i got you now

            1 Reply Last reply
            0
            • U Offline
              U Offline
              umen242
              wrote on last edited by
              #8

              i tried to put the QApplication as the parent of the QSystemTrayIcon and i saw it inherited fro QWidget
              but it gives me error it can't cast from from QApplication to QWidget .

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #9

                QApplication does not inherit from QWidget. In inherits from QObject (just like QWidget does). Furtunately, QSystemTrayIcon takes a QObject* as the parent argument. So why do you need to try to cast QApplication to a QWidget? That will not work, and is not needed.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  umen242
                  wrote on last edited by
                  #10

                  my mistake , thanks

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    umen242
                    wrote on last edited by
                    #11

                    hi again , i have another problem here .
                    what to do with the new QMenu that is set with the ContextMenu , it takes only QWidget as parent.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #12

                      Actually, it also takes a 0 pointer as a parent. You'd just need to make sure you delete the menu yourself...

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        umen242
                        wrote on last edited by
                        #13

                        Thanks for your help

                        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