Search code examples
c++qtsignalssignals-slotsslots

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.


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.