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
| class Toto : public QObject
{
Q_OBJECT
public slots:
void exec(){
//I represent the real process (image processing on very large image) with an infinite loop
while(1==1);
}
};
int main(int argc, char *argv[])
{
QApplication aa(argc, argv);
QThread * t1 = new QThread;
Toto * toto1 = new Toto;
QThread * t2 = new QThread;
Toto * toto2 = new Toto;
QPushButton push;
push.show();
toto1->moveToThread(t1);
toto2->moveToThread(t2);
QMetaObject::invokeMethod(toto1, "exec", Qt::QueuedConnection);
QMetaObject::invokeMethod(toto2, "exec", Qt::QueuedConnection);
QApplication::connect(&push, SIGNAL(pressed()), t1,SLOT(terminate()), Qt::QueuedConnection);
QApplication::connect(&push, SIGNAL(pressed ()), t2,SLOT(terminate()), Qt::QueuedConnection);
t2->start();
t1->start();
return aa.exec();
} |
Partager