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. Detect Whether the index Change in ComboBox is by user or programatically
Forum Updated to NodeBB v4.3 + New Features

Detect Whether the index Change in ComboBox is by user or programatically

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 7.1k 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.
  • D Offline
    D Offline
    deepakkakkeel
    wrote on last edited by
    #1

    Hi,

    I have a QComboBox. I have connected SIGNAL currentIndexChanged to a SLOT update(). So may is there any way that i can check whether the currentIndexChanged is called because of user interaction on comboBox or programatically.

    Thanks
    Deepak

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      When you change it programatically, "block signals":http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#blockSignals and update by hand. You can pass a boolean value to indicate that, for example. So:
      @
      combobox->blockSignals(true);
      // change the index here. Combobox will not send any signals!
      // so you need to call your slot yourself - here is where you can inform it that it's not user change
      combobox->blockSignals(false);
      @

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deepakkakkeel
        wrote on last edited by
        #3

        Hi,

        In my piece of code the SIGNAL currentIndexChanged() is called which will call my SLOT update(). So inside that function i need to check whether the index change has been caused by user or programatically.

        Deepak.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yeah, just add a boolean to your update:
          @
          void YourClass::update(bool changeByUser = false);

          /// then
          combobox->blockSignals(true);
          // change the index here. Combobox will not send any signals!
          update(true);
          combobox->blockSignals(false);
          @

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            butterface
            wrote on last edited by
            #5

            Some time ago I read you should not use blockSignals but disconnect instead. Is that true?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I don't know, I have not heard anything said against blockSignals, please provide a link if you have one - I'm interested in knowing the reason. Documentation does not hint at blockSignals being bad in any way.

              You can disconnect if you prefer, it takes just a bit more typing.

              (Z(:^

              1 Reply Last reply
              0
              • B Offline
                B Offline
                butterface
                wrote on last edited by
                #7

                Of course if I can find the link again.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vezprog
                  wrote on last edited by
                  #8

                  I have used blockSignals in multiple occasions for combo boxes as well as radio buttons for state changes. It has always worked perfect for me!

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    butterface
                    wrote on last edited by
                    #9

                    It is some time ago and I cannot find the link anymore. It is also possible that either the link or I was wrong.
                    Apparently if no one knows such a fact it is not correct.

                    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