Home · All Classes · alphabetical Classes List · Modules · Functions ·

QxtSignalWaiter Class Reference
[Kit]

Wait until a signal ocured. More...

Public Member Functions

Static Public Member Functions

Protected Member Functions


Detailed Description

Wait until a signal ocured.

In many cases, writing code that assumes certain actions are synchronous is considerably simpler than breaking your function into multiple blocks and using signals and slots to connect them all. Using this class, QSignalWaiter::wait will block until a certain signal is emitted and then return. The return value is true if the signal was caught, or false if a user-specified timeout elapses before catching the signal.

void MyObject::myFunction() {
    QxtSignalWaiter waiter(myOtherObject, SIGNAL(longProcessFinished()));
    myOtherObject->longProcess();
    if(waiter.wait(5000))
        doSomething(myOtherObject->information());
    else
        QMessageBox::information(0, "MyObject", "Timed out while waiting on longProcessFinished()", QMessageBox::Ok);
}

Bug:
QxtSignalWaiter is, sadly, not reentrant. In particular, only one QxSignalWaiter object can be safely waiting at a time. If a second QxSignalWaiter is used while the first is waiting, the first will not return until the second has timed out or successfully caught its signal. A later revision of the class may be able to solve this problem. Until then, be careful not to rely on two QxtSignalWaiter objects at the same time.


Constructor & Destructor Documentation

QxtSignalWaiter::QxtSignalWaiter ( const QObject *  sender, const char *  signal )

default constructor Creates a QSignalWaiter and sets the default signal to sender::signal.



Member Function Documentation

bool QxtSignalWaiter::wait ( int  msec = -1 )

wait for signal Waits for the signal sender::signal to be emitted. If msec is not -1, wait() will return after msec milliseconds. If a signal is not specified, the default signal specified in the constructor is used instead. If no default signal was specified in the constructor, wait() will block until the timeout has elapsed. If no timeout was specified, wait() will return immediately.
Returns true if the signal was caught, false if it timed out.
This function is not reentrant.



(c) 2007A.Picciani and A.Higerd LGPL
libqxt 0.2