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 670 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.
  • K Offline
    K Offline
    Kaguro
    wrote on 25 Oct 2021, 10:21 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!

    P 1 Reply Last reply 25 Oct 2021, 11:10
    0
    • K Kaguro
      25 Oct 2021, 11:35

      @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?

      J Offline
      J Offline
      JonB
      wrote on 25 Oct 2021, 11:57 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.

      K 1 Reply Last reply 25 Oct 2021, 12:03
      1
      • K Kaguro
        25 Oct 2021, 10:21

        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!

        P Offline
        P Offline
        Pl45m4
        wrote on 25 Oct 2021, 11:10 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

        K 1 Reply Last reply 25 Oct 2021, 11:35
        0
        • P Pl45m4
          25 Oct 2021, 11:10

          @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"));
          
          K Offline
          K Offline
          Kaguro
          wrote on 25 Oct 2021, 11:35 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?

          J P 2 Replies Last reply 25 Oct 2021, 11:57
          0
          • K Kaguro
            25 Oct 2021, 11:35

            @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?

            J Offline
            J Offline
            JonB
            wrote on 25 Oct 2021, 11:57 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.

            K 1 Reply Last reply 25 Oct 2021, 12:03
            1
            • J JonB
              25 Oct 2021, 11:57

              @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.

              K Offline
              K Offline
              Kaguro
              wrote on 25 Oct 2021, 12:03 last edited by
              #5

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

              1 Reply Last reply
              0
              • K Kaguro
                25 Oct 2021, 11:35

                @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?

                P Offline
                P Offline
                Pl45m4
                wrote on 25 Oct 2021, 12:03 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

                J 1 Reply Last reply 25 Oct 2021, 12:26
                0
                • P Pl45m4
                  25 Oct 2021, 12:03

                  @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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 25 Oct 2021, 12:26 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?

                  P 1 Reply Last reply 25 Oct 2021, 12:38
                  0
                  • J JonB
                    25 Oct 2021, 12:26

                    @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?

                    P Offline
                    P Offline
                    Pl45m4
                    wrote on 25 Oct 2021, 12:38 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

                    J 1 Reply Last reply 25 Oct 2021, 12:41
                    0
                    • P Pl45m4
                      25 Oct 2021, 12:38

                      @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)

                      J Offline
                      J Offline
                      JonB
                      wrote on 25 Oct 2021, 12:41 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.

                      P 1 Reply Last reply 25 Oct 2021, 13:25
                      2
                      • J JonB
                        25 Oct 2021, 12:41

                        @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.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 25 Oct 2021, 13:25 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

                        1/10

                        25 Oct 2021, 10:21

                        • Login

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