C++ (Qt)class CWaitLoop : public QEventLoop{ Q_OBJECTpublic: explicit CWaitLoop(QObject *parent = nullptr) : QEventLoop(parent) {} int wait(int msecs); public slots: void exitSlot(int code) { QEventLoop::exit(code); }}; int CWaitLoop::wait(int msecs){ QTimer timer; timer.setSingleShot(true); timer.start(msecs); connect(&timer, &QTimer::timeout, this, &CWaitLoop::quit); return exec();} class AnyClass {...signals: void stopWaiting(int);}; ... AnyClass any; CWaitLoop waitLoop; connect(&any, &AnyClass::stopWaiting, &waitLoop, &CWaitLoop::exitSlot); int ret = waitLoop.wait(1000);