2017-02-14 144 views
-1

enter image description here我不知道爲什麼我得到錯誤或這些語句。當我爲x86_64系統編譯它時,相同的代碼工作正常,但當我將目標更改爲Beaglebone Black並切換到Angstrom工具鏈時,QTcreator開始在這些行中給出錯誤。編譯QT代碼時出現奇怪和未知的錯誤

//connect(process, &QProcess::readyReadStandardError, [=]{ 
ui->textBrowser->append(process->readAllStandardError()); 
}); 
connect(process, &QProcess::readyReadStandardOutput, [=]{ 
ui->textBrowser->append(process->readAllStandardOutput()); 
}); 

錯誤用於表達式「[=]」。事實上,我不知道爲什麼會出現這個錯誤。這可能與版本有關,bcoz BBB有qt4-embedded。任何幫助,將不勝感激。

+0

您檢查您添加CONFIG + = C++ 14? – 0Tech

+0

https://wiki.qt.io/New_Signal_Slot_Syntax僅適用於qt5 – user3528438

+0

我正在使用CONFIG + = C++ 11 – Learner

回答

1

將信號連接到C++ 11 lambda的語法已添加到Qt 5.由於以前的版本(Qt4)未定義connect()的正確簽名,因此無法使用它。你應該將您的代碼以匹配正確的語法:

connect(process, SIGNAL(readyReadStandardError()), receiver, SLOT(yourCustomSlot())); 

隨着聲明如下插槽:

class MyReceiverClass { 

slots: 
    void yourCustomSlot() { 
     ui->textBrowser->append(process->readAllStandardOutput()); 
    } 
}; 
+0

你能幫助我更多一點嗎?添加一個不適合我的自定義插槽,如果我在mainwindow.h中添加插槽會出現錯誤 我已將mainwindow.cpp中的原始連接線替換爲您建議的連接線,並在mainwindow.h中添加了類MyReceiverClass。代碼不會被編譯。 – Learner

+0

你應該寫一個新的問題 – Antwane