Search code examples
c++qtslot

No such Slot/Signals (Qt)


Object::connect: No such signal RollsRoyceTab::signal_aValueChange(int aValue)

In the following class:

class RollsRoyceTab : public QWidget
 {
     Q_OBJECT
 public:
     RollsRoyceTab(QWidget *parent = 0);
 public slots:
     void aValueChange(int);
     void rrValuesHolder(int aValue, int bValue, int cValue);
signals:
     void signal_aValueChange(int aValue);

 private:
     int aValue, bValue, cValue;
 };

And somewhere the connect, like:

connect(this,SIGNAL(signal_aValueChange(int aValue)),
    this,SLOT(rrValuesHolder(int aValue, int bValue, int cValue))); 

These are the actual implementations:

 void RollsRoyceTab::aValueChange(int aValue)
 {
     ...
     emit signal_aValueChange(aValue);
 }

void RollsRoyceTab::rrValuesHolder(int aValue, int bValue, int cValue)
 {
     qDebug() << aValue;
 }

What is the poper way to write the connect?
connect(... this,SLOT(rrValuesHolder(int aValue, int bValue, int cValue)));
or need write only one value SLOT(rrValuesHolder(int aValue))?


Solution

  • First: signals and slots in QObject::connect() should be without variables names.

    Second: You can't connect signal with one argument with SLOT with three arguments. SIGNAL must not have fewer arguments than the SLOT.

    It should be for e.g.:

    connect(this,SIGNAL(signal_aValueChange(int)),this,SLOT(rrValuesHolder(int)));
    

    And it's simply explanation for that. If you emit signal with one argument (for e.g. QString) how would slot know what are others two arguments? For me it's logical.