简体   繁体   English

没有这样的插槽/信号(Qt)

[英]No such Slot/Signals (Qt)

Object::connect: No such signal RollsRoyceTab::signal_aValueChange(int aValue) ?????? 对象::连接:没有这样的信号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))); 并连接(...... this,SLOT(rrValuesHolder(int aValue,int bValue,int cValue)))); or need write only one value SLOT(rrValuesHolder(int aValue)) ? 还是只需要写一个值SLOT(rrValuesHolder(int aValue))?

First: signals and slots in QObject::connect() should be without variables names. 首先:QObject :: connect()中的信号和插槽应该没有变量名称。

Second: You can't connect signal with one argument with SLOT with three arguments. 第二:您无法将信号与带有三个参数的SLOT连接到一个参数。 SIGNAL must not have fewer arguments than the SLOT. SIGNAL的自变量不得少于SLOT。

It should be for eg: 它应该用于例如:

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 eg QString) how would slot know what are others two arguments? 如果您发出带有一个自变量的信号(例如QString),插槽将如何知道另外两个自变量? For me it's logical. 对我来说,这是合乎逻辑的。

"SIGNAL() macro must NOT have fewer arguments than the signature passed to the SLOT() macro. “ SIGNAL()宏的自变量不得少于传递给SLOT()宏的签名。

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)) 我相信你应该把value SLOT(rrValuesHolder(int))叫做value SLOT(rrValuesHolder(int))

Reference: http://qt-project.org/doc/qt-4.8/signalsandslots.html 参考: 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! 编辑:Blood包括我忽略的另一条信息,Signals和Slots应该没有变量名地连接!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM