// implements the communication protocol
// only PrinterThread should use it
class PrinterController
: public QObject{
Q_OBJECT
public:
...
public slots:
void doSomething();
signals:
void done();
...
};
// provides printer interface to the rest of the application
class PrinterThread
: public QThread{
Q_OBJECT
public:
...
signals:
void done();
void doSomething();
}
void PrinterThread::run()
{
PrinterController controller;
connect( this, SIGNAL( doSometing() ), &controller, SLOT( doSomething() ) );
connect( &controller, SIGNAL( done() ), this, SIGNAL( done() ) );
exec();
}
...
connect( printerThread, SIGNAL( done() ), someObject, SLOT( continueWork() ) );
printerThread->doSomething(); // this behaves just as a non-blocking call
...