class O2;
{
Q_OBJECT
public:
{
olocal->moveToThread(m_thread);
connect(m_thread, SIGNAL(started()), olocal, SLOT(start()));
connect(olocal, SIGNAL(finished()), m_thread, SLOT(quit()));
....
}
~O1() {
olocal->finish();
m_thread->wait();
delete olocal;
delete m_thread;
}
signals:
void mysignal();
};
{
Q_OBJECT
public:
O2(O1 *parent) : q_ptr(parent) {}
signals:
void finished();
public slots:
void start
() { b_start
= true;
QTimer::singleShot(0,
this,
SLOT(run
()));
} void finish() { b_finish = true; }
void run() {
if(b_finished) {
emit finished();
return;
}
// do some staff
if( /* something */)
emit q_ptr->mysignal();
if(b_start)
QTimer::singleShot(0,
this, run
());
}
};
class O2;
class O1 : public QObject
{
Q_OBJECT
public:
O1(QObject *parent = 0): olocal(new O2(this)), QObject(parent)
{
m_thread = new QThread;
olocal->moveToThread(m_thread);
connect(m_thread, SIGNAL(started()), olocal, SLOT(start()));
connect(olocal, SIGNAL(finished()), m_thread, SLOT(quit()));
....
}
~O1() {
olocal->finish();
m_thread->wait();
delete olocal;
delete m_thread;
}
signals:
void mysignal();
};
class O2 : public QObject
{
Q_OBJECT
public:
O2(O1 *parent) : q_ptr(parent) {}
signals:
void finished();
public slots:
void start() { b_start = true; QTimer::singleShot(0, this, SLOT(run())); }
void finish() { b_finish = true; }
void run() {
if(b_finished) {
emit finished();
return;
}
// do some staff
if( /* something */)
emit q_ptr->mysignal();
if(b_start)
QTimer::singleShot(0, this, run());
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks