2013-03-11 93 views
0

Object :: connect:沒有這樣的信號RollsRoyceTab :: signal_aValueChange(int aValue) ??????沒有這樣的插槽/信號(Qt)

我有

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; 

} 

並連接(......此,SLOT(rrValuesHolder(INT安勤,INT bValue,INT cValue)));或者只需要寫一個值SLOT(rrValuesHolder(int aValue))?

回答

3

第一:QObject :: connect()中的信號和插槽應該沒有變量名稱。

第二:不能用帶三個參數的SLOT連接一個參數的信號。 SIGNAL的參數不能少於SLOT。

它應該是例如: -

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

而且它只是解釋說。如果你用一個參數發射信號(例如QString),slot如何知道其他兩個參數是什麼?對我來說這是合乎邏輯的。

+0

好的。 connect(this,SIGNAL(signal_aValueChange(int,int,int)),this,SLOT(rrValuesHolder(int,int,int)));發出signal_aValueChange(aValue,bValue,cValue); – 2013-03-11 19:16:28

0

「SIGNAL()宏不能有更少的參數比傳遞到SLOT()宏簽名

所有這些將工作:

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

這不起作用:

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

我相信你應該叫爲value SLOT(rrValuesHolder(int))

和借鑑e:http://qt-project.org/doc/qt-4.8/signalsandslots.html

編輯:血液包括一個額外的信息,我忽略了,信號和插槽應該連接沒有變量名稱!