Das versuche ich zu realisieren in dem mein QThread für jede Aufgabe einen Slot bekommt (connectToServer(), login(), ...). Damit das so funktioniert, ist natürlich vorausgesetzt das die Slots auch in meinem Thread ausgeführt werden, und nicht in dem Thread von dem ich die Slots aufrufe.
Um das zu testen, habe ich einen QThread mit einem block() Slot erstellt, in dem eine while(true) Schleife gestartet wird. Den Slot verbinde ich mit einem Signal von einem QPushButton mit dem ConnectionType QueuedConnection und erwarte jetzt, das sobald ich den Button klicke, die while schleife in meinem Thread läuft, und meine GUI nicht blockiert wird, sie wird aber blockiert was ich nicht verstehe, denn in der Dokumentation steht:
With queued connections, the slot is invoked when control returns to the event loop of the thread to which the object belongs. The slot is executed in the thread where the receiver object lives.
Code: Alles auswählen
class MyThread : public QThread
{
Q_OBJECT
public:
void run();
public slots:
void block();
};
void MyThread::run()
{
exec();
}
void MyThread::block()
{
qDebug("starting to block");
while(true);
}Code: Alles auswählen
int main( int argc, char **argv )
{
QApplication app(argc, argv);
QPushButton button("push me");
button.show();
MyThread thread;
QObject::connect(&button, SIGNAL(clicked()), &thread, SLOT(block()), Qt::QueuedConnection);
thread.start();
return app.exec();
}Seht ihr meinen Fehler?