Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

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

    General and Desktop
    4
    9
    5895
    Loading More Posts
    • 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
      deepakkakkeel last edited by

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 0
        • D
          deepakkakkeel last edited by

          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 Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            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 Reply Quote 0
            • B
              butterface last edited by

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

              1 Reply Last reply Reply Quote 0
              • sierdzio
                sierdzio Moderators last edited by

                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 Reply Quote 0
                • B
                  butterface last edited by

                  Of course if I can find the link again.

                  1 Reply Last reply Reply Quote 0
                  • V
                    vezprog last edited by

                    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 Reply Quote 0
                    • B
                      butterface last edited by

                      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 Reply Quote 0
                      • First post
                        Last post