Zhang LongQI
Zhang LongQI

Reputation: 494

why a connection's signal have argument but slot doesn't have one?

Qt 4.8.1,The original code just like this:

connect(this->m_CodeMemoryComboBox, SIGNAL(currentIndexChanged(QString)),
      this, SLOT(updateCodeMemoryFormate()));

This really confuse me,[question]Can I pass an argument to the slot function when using QObject::connect? That told me the argument should be match,but what happen here,the code will wrong if I remove that argument.

Upvotes: 0

Views: 484

Answers (2)

shofee
shofee

Reputation: 2129

The QT Doc says,

The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)

Upvotes: 1

The Qt documentation describes this. Search for "(In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)" under the heading "Signals and slots"

Basically, you can connect an N-parameter signal to an M-parameter slot if M <= N and the first M parameters match in type. Any leftover arguments from the signal are ignored by the slot.

Upvotes: 4

Related Questions