0

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.

Zhang LongQI
  • 494
  • 1
  • 11
  • 25

2 Answers2

4

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.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
  • 5
    @benhuan, if you have `signal(a, b, c, d)` and `slot(a, b)` the arguments `c` and `d` will be ignored. – vahancho Sep 23 '13 at 13:42
1

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

shofee
  • 2,079
  • 13
  • 30