summaryrefslogtreecommitdiffstats
path: root/objects/signalwaiter.cpp
blob: 3550e5b62d38feec33cf4283cdf3978c4b9e51fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "signalwaiter.h"

#include <QElapsedTimer>
#include <QCoreApplication>

namespace Scripting {
namespace Internal {

SignalWaiter::SignalWaiter(QObject *parent) :
    QObject(parent), m_received(false)
{
}

bool SignalWaiter::wait(QObject *object, const char *signal, int msecs)
{
    connect( object, signal, this, SLOT(slotReceived()));
    QElapsedTimer timer;
    timer.start();
    while ( !m_received && timer.elapsed() < msecs ) {
        qApp->processEvents(QEventLoop::ExcludeUserInputEvents, 100);
    }
    return m_received;
}

void SignalWaiter::slotReceived()
{
    m_received = true;
}

} // namespace Internal
} // namespace Scripting