在同步模式下等待带参数的信号

时间:2017-11-02 11:25:33

标签: signals-slots qt4.8

当我需要在同步模式下等待信号时,以下代码可以正常工作。

    QEventLoop signalWaitLoop;

    connect(&emmiter, SIGNAL(signalValue(quint8)), &signalWaitLoop, SLOT(quit()));

    emmiter.sendSignal();
    signalWaitLoop.exec();

如何从信号中很好地检索发送的值(quint8)

1 个答案:

答案 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)));