Ok, here is the code as requested:
{
TransportObject transportObject;
public slots:
objectIn(TransportObject);
}
{
moveTothread(this); // Thread handles it's own event loop hack.
start();
}
Thread::run()
{
forever
{
process(transportObject); // do something with transportObject
msleep(10);
}
}
Thread::objectIn(TransportObject to)
{
this->transportObject = to;
}
main
{
Thread thread;
TransportObject transportObject;
connect(this, SIGNAL(objectOut(TransportObject)), &thread, SLOT(objectIn(TransportObject)));
...
emit objectOut(transportObject);
}
class Thread : QThread
{
TransportObject transportObject;
public slots:
objectIn(TransportObject);
}
Thread::Thread(QObject *parent) : QThread(parent)
{
moveTothread(this); // Thread handles it's own event loop hack.
start();
}
Thread::run()
{
forever
{
process(transportObject); // do something with transportObject
QApplication::processEvents(); // handle pending events
msleep(10);
}
}
Thread::objectIn(TransportObject to)
{
this->transportObject = to;
}
main
{
Thread thread;
TransportObject transportObject;
connect(this, SIGNAL(objectOut(TransportObject)), &thread, SLOT(objectIn(TransportObject)));
...
emit objectOut(transportObject);
}
To copy to clipboard, switch view to plain text mode
Bookmarks