No such Slot/Signals (Qt)

坚强是说给别人听的谎言 提交于 2019-11-27 08:53:44

问题


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

I have

class RollsRoyceTab : public QWidget
 {
     Q_OBJECT
 public:
     RollsRoyceTab(QWidget *parent = 0);
 public slots:
     void aValueChange(int);
     void bValueChange(int);
     void cValueChange(int);
     void rrValuesHolder(int aValue, int bValue, int cValue);
signals:
     void signal_aValueChange(int aValue);
     void signal_bValueChange(int bValue);
     void signal_cValueChange(int cValue);
 private:
.........
     int aValue, bValue, cValue;
 };

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

 void RollsRoyceTab::aValueChange(int aValue)
 {
     lcdAL->display(aValue);
     lcdAR->display(100 - aValue);

     emit signal_aValueChange(aValue);
 }

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

 }

and connect(...... this,SLOT(rrValuesHolder(int aValue, int bValue, int cValue))); or need write only one value SLOT(rrValuesHolder(int aValue)) ?


回答1:


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.




回答2:


"SIGNAL() macro must NOT have fewer arguments than the signature passed to the SLOT() macro.

All of these would work:

connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(Qbject*)));
connect(sender, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed()));
connect(sender, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));

This does not work:

connect(sender, SIGNAL(destroyed()), this, SLOT(objectDestroyed(QObject*)));

I believe you should call as value SLOT(rrValuesHolder(int))

Reference: http://qt-project.org/doc/qt-4.8/signalsandslots.html

EDIT: Blood included one additional piece of information that I neglected, Signals and Slots should be connected without variable names!



来源:https://stackoverflow.com/questions/15346428/no-such-slot-signals-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!