Home > Mobile >  Qt event triggers twice
Qt event triggers twice

Time:09-27

Qt when setting signals and slots to perform two slot function
I was originally written like this:
The
reference
QObject: : connect (UI - & gt; CboTuoLuoYi_X, SIGNAL (stateChanged (int)), and this, SLOT (on_cboTuoLuoYi_X_stateChanged (int)));

When I change to the following:
The
reference
QObject: : connect (UI - & gt; CboTuoLuoYi_X, SIGNAL (stateChanged (int)), and this, SLOT (cboTuoLuoYi_X_stateChanged (int)));

Perform a,

Consult the reason, tell me the reason which bosses

CodePudding user response:

[static] void QMetaObject: : connectSlotsByName (QObject * object)
Searches recursively for all child objects of the given object, and connects matching signals from them to slots of the object that follow the following form:

Void on_ & lt; The object name> _ & lt; Signal name> (
Let 's assume our object from a child object of type QPushButton with the object name. For the slot to catch the button' s clicked () signal whenever:

Void on_button1_clicked ();

If the object itself has a properly set the object name, its own signals are also connected to its respective slots.

CodePudding user response:

. You can go to have a look at * _ui h header file setupUi function the last line, generally have a QMetaObject: : connectSlotsByName calls,

CodePudding user response:

On_cboTuoLuoYi_X_stateChanged QT compiler, according to the groove function name automatically match, then you connect again,

CodePudding user response:

Qt itself will have to provide a standard format by default slot function, similar on_cboTuoLuoYi_X_stateChanged this, even if you don't have in your class member function definition will exist, you connect the two
  •  Tags:  
  • Qt
  • Related