{
Q_OBJECT
public slots:
void exec(){
//I represent the real process with an infinite loop
while(1==1);
}
};
int main(int argc, char *argv[])
{
Toto * toto1 = new Toto;
Toto * toto2 = new Toto;
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();
}
class Toto : public QObject
{
Q_OBJECT
public slots:
void exec(){
//I represent the real process 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();
}
To copy to clipboard, switch view to plain text mode
The problem is my infinite loop is not interrupted when I press the buttom.
Bookmarks