سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top