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. System Tray Icon Example bug if I change the current icon index to 0
QtWS25 Last Chance

System Tray Icon Example bug if I change the current icon index to 0

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 671 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.
  • KaguroK Offline
    KaguroK Offline
    Kaguro
    wrote on last edited by
    #1

    Hi Guys!
    I have a problem in the System Tray Icon Example in qt.
    If I change this row:

    iconComboBox->setCurrentIndex(1);
    

    to:

    iconComboBox->setCurrentIndex(0);
    

    after this i have an error message in the debug:
    "QSystemTrayIcon::setVisible: No Icon set"
    And i dont see the icon in the tray menu, but if i set the default index to 1 as the original example, its working.
    But Why? I dont understand what is the different between the 0. QComboBox icon and the 1. one?
    Thanks your help!

    Pl45m4P 1 Reply Last reply
    0
    • KaguroK Kaguro

      @Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:

      connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);

      Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @Kaguro
      If you have code which you want run on QComboBox::currentIndexChanged but also for the initial situation, it is easiest to call it explicitly when you start.

      Alternatively QComboBox::::currentIndex() starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo.

      KaguroK 1 Reply Last reply
      1
      • KaguroK Kaguro

        Hi Guys!
        I have a problem in the System Tray Icon Example in qt.
        If I change this row:

        iconComboBox->setCurrentIndex(1);
        

        to:

        iconComboBox->setCurrentIndex(0);
        

        after this i have an error message in the debug:
        "QSystemTrayIcon::setVisible: No Icon set"
        And i dont see the icon in the tray menu, but if i set the default index to 1 as the original example, its working.
        But Why? I dont understand what is the different between the 0. QComboBox icon and the 1. one?
        Thanks your help!

        Pl45m4P Online
        Pl45m4P Online
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:

        I dont understand what is the different between the 0. QComboBox icon and the 1. one?

        This line

            connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
        

        and the corresponding function

        void Window::setIcon(int index)
        {
            QIcon icon = iconComboBox->itemIcon(index);
            trayIcon->setIcon(icon);
            setWindowIcon(icon);
        
            trayIcon->setToolTip(iconComboBox->itemText(index));
        }
        

        The item at index 0 probably has no icon.

        Edit:

        Icon 0 should be the "bad" icon... Do you see that icon in your combobox and are you able to select it manually?

            iconComboBox = new QComboBox;
            iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad"));
            iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart"));
            iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash"));
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        KaguroK 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:

          I dont understand what is the different between the 0. QComboBox icon and the 1. one?

          This line

              connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
          

          and the corresponding function

          void Window::setIcon(int index)
          {
              QIcon icon = iconComboBox->itemIcon(index);
              trayIcon->setIcon(icon);
              setWindowIcon(icon);
          
              trayIcon->setToolTip(iconComboBox->itemText(index));
          }
          

          The item at index 0 probably has no icon.

          Edit:

          Icon 0 should be the "bad" icon... Do you see that icon in your combobox and are you able to select it manually?

              iconComboBox = new QComboBox;
              iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad"));
              iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart"));
              iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash"));
          
          KaguroK Offline
          KaguroK Offline
          Kaguro
          wrote on last edited by
          #3

          @Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:

          connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);

          Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?

          JonBJ Pl45m4P 2 Replies Last reply
          0
          • KaguroK Kaguro

            @Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:

            connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);

            Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @Kaguro
            If you have code which you want run on QComboBox::currentIndexChanged but also for the initial situation, it is easiest to call it explicitly when you start.

            Alternatively QComboBox::::currentIndex() starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo.

            KaguroK 1 Reply Last reply
            1
            • JonBJ JonB

              @Kaguro
              If you have code which you want run on QComboBox::currentIndexChanged but also for the initial situation, it is easiest to call it explicitly when you start.

              Alternatively QComboBox::::currentIndex() starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo.

              KaguroK Offline
              KaguroK Offline
              Kaguro
              wrote on last edited by
              #5

              @JonB Yeah thanks your help! This will be the solution! :)
              Thanks Guys! @JonB @Pl45m4

              1 Reply Last reply
              0
              • KaguroK Kaguro

                @Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:

                connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);

                Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?

                Pl45m4P Online
                Pl45m4P Online
                Pl45m4
                wrote on last edited by
                #6

                @Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:

                Is there any chance the currentIndexChanged event is the issue?

                The signal even gets emitted when you change the idex programmatically.

                • https://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged

                So something else must be wrong or you are doing something else wrong.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                JonBJ 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:

                  Is there any chance the currentIndexChanged event is the issue?

                  The signal even gets emitted when you change the idex programmatically.

                  • https://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged

                  So something else must be wrong or you are doing something else wrong.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #7

                  @Pl45m4
                  I'm only guessing for the OP, but looking https://doc.qt.io/qt-5/qtwidgets-desktop-systray-example.html#window-class-implementation the connect(iconComboBox, &QComboBox::currentIndexChanged) gets executed after iconComboBox gets populated? So if he wants it to be called initially he needs to do either of what I suggested?

                  Pl45m4P 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Pl45m4
                    I'm only guessing for the OP, but looking https://doc.qt.io/qt-5/qtwidgets-desktop-systray-example.html#window-class-implementation the connect(iconComboBox, &QComboBox::currentIndexChanged) gets executed after iconComboBox gets populated? So if he wants it to be called initially he needs to do either of what I suggested?

                    Pl45m4P Online
                    Pl45m4P Online
                    Pl45m4
                    wrote on last edited by
                    #8

                    @JonB

                    I dont think it's necessary, because iconComboBox->setCurrentIndex(1 /* or 0 */); is called after the connection was set up and the combobox was filled.
                    Then it should emit currentIndexChanged anyways... but I could be wrong :)

                    (You would face the same situation when you add items to your comboBox in Design-Mode. The items are there, before you make any connections to your instances. setupUI would create the items and this is usually called first in any c'tor)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    JonBJ 1 Reply Last reply
                    0
                    • Pl45m4P Pl45m4

                      @JonB

                      I dont think it's necessary, because iconComboBox->setCurrentIndex(1 /* or 0 */); is called after the connection was set up and the combobox was filled.
                      Then it should emit currentIndexChanged anyways... but I could be wrong :)

                      (You would face the same situation when you add items to your comboBox in Design-Mode. The items are there, before you make any connections to your instances. setupUI would create the items and this is usually called first in any c'tor)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #9

                      @Pl45m4
                      I have not tested this, and you may know more than I. But after the initial population the currentIndex will already be on 0, only then is the connect() executed. Then iconComboBox->setCurrentIndex(0) will not raise currentIndexChanged signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?

                      Your design-mode description is indeed correct, and in this case again currentIndexChanged slots will not be called.

                      Pl45m4P 1 Reply Last reply
                      2
                      • JonBJ JonB

                        @Pl45m4
                        I have not tested this, and you may know more than I. But after the initial population the currentIndex will already be on 0, only then is the connect() executed. Then iconComboBox->setCurrentIndex(0) will not raise currentIndexChanged signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?

                        Your design-mode description is indeed correct, and in this case again currentIndexChanged slots will not be called.

                        Pl45m4P Online
                        Pl45m4P Online
                        Pl45m4
                        wrote on last edited by
                        #10

                        @JonB said in System Tray Icon Example bug if I change the current icon index to 0:

                        Then iconComboBox->setCurrentIndex(0) will not raise currentIndexChanged signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?

                        Yes, now I understand what you meant before :)


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        1

                        • Login

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