当我需要在同步模式下等待信号时,以下代码可以正常工作。
QEventLoop signalWaitLoop;
connect(&emmiter, SIGNAL(signalValue(quint8)), &signalWaitLoop, SLOT(quit()));
emmiter.sendSignal();
signalWaitLoop.exec();
如何从信号中很好地检索发送的值(quint8)?
答案 0 :(得分:0)
制作自己的课程:
class MyEventLoop : public QEventLoop
{
Q_OBJECT
public:
MyEventLoop(QObject * parent = 0)
: QEventLoop(parent) {}
public slots:
void mySlot(quint8 value) {
// something with value
quit();
}
}
MyEventLoop signalWaitLoop;
connect(&emmiter, SIGNAL(signalValue(quint8)), &signalWaitLoop, SLOT(mySlot(quint8)));