You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, February 23rd 2012, 11:04am

How to Stop QComboBox Responding to Programmatic Content Changes

Hi,

I'm currently developing an app in which a user changing the index of one QComboBox causes the contents of a second QComboBox to update. The second QComboBox can also be set by the user independently of the first QComboBox.

The problem I'm having is that when the index of the first QComboBox is changed, the update of the contents of the second QComboBox is calling its currentIndexChanged signal which is then changing a program variable before all the contents of the second QComboBox are updated.

Is there a way to stop the second QComboBox responding to currentIndexChanged when this happens programmatically but still have it work when it's changed by the user?

Cheers,

Chris

2

Thursday, February 23rd 2012, 11:27am

I actually figured out a quick way to do this - just disconnect the signal while the second QComboBox is updated and then connect it.

max2u

Beginner

  • "max2u" is male

Posts: 4

Location: JO

Occupation: Programming

  • Send private message

3

Thursday, February 23rd 2012, 12:51pm

greetings,
in the class that has the QComboBox add something like bool myComboBoxModifiedByCode; and make its default value in the constructor to false, when ever you are changing the QComboBox current index programmatically set it to true, and after you are done set it back to false and the beginning of the slot called by the QComboBox::currentIndexChanged() signal validate if myComboBoxModifiedByCode is true just return and don't continue with the rest of the logic.

hope this works out for you ^_^.