Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top