When come many signals, slot waits for finish and it starts another
-
Hi,
I have gui app. I created 3 QUdpSocket which listen data on specific port and this data control gui app. This 3 sockets use one slot:connect(socket1, &QUdpSocket::readyRead, this, &MyClass::parseData); connect(socket2, &QUdpSocket::readyRead, this, &MyClass::parseData); connect(socket3, &QUdpSocket::readyRead, this, &MyClass::parseData);
And now when i immadietly send 3 frames on sockets i want to achive that result:
When 1 slots finish job, start second, when second finishes start third but these actions don't block GUI.
Greetings -
Assuming MyClass is not your main window, move MyClass to another thread using moveToThread, and start the thread. It should provide you with what you're looking for.
In your case it might not be as simple as that. When you make objects in one thread, moving a parent object to another thread will not work. Usually what I do is add a "start" function slot that will instantiate all the objects. I connected the started signal from the thread I move to to the start slot. this will execute the start method on the new thread once that thread is started.
here is an example of what I mean:
QThread handlerThread; LocalServerHandler mLocalServerHandler; QObject::connect(&app,&QGuiApplication::aboutToQuit,&handlerThread,&QThread::quit); QObject::connect(&app,&QGuiApplication::aboutToQuit,&handlerThread,&QThread::deleteLater); mLocalServerHandler.moveToThread(&handlerThread); QObject::connect(&handlerThread,&QThread::started,&mLocalServerHandler,&LocalServerHandler::start); QObject::connect(&app,&QGuiApplication::aboutToQuit,&mLocalServerHandler,&LocalServerHandler::deleteLater);
The event loop in that new thread will still run first event in first event out but your main event loop will keep the UI unlocked.
-
Hi,
I have gui app. I created 3 QUdpSocket which listen data on specific port and this data control gui app. This 3 sockets use one slot:connect(socket1, &QUdpSocket::readyRead, this, &MyClass::parseData); connect(socket2, &QUdpSocket::readyRead, this, &MyClass::parseData); connect(socket3, &QUdpSocket::readyRead, this, &MyClass::parseData);
And now when i immadietly send 3 frames on sockets i want to achive that result:
When 1 slots finish job, start second, when second finishes start third but these actions don't block GUI.
Greetings@Bondrusiek What exactly is your question? Behaviour you described is sound, works as it should.
If you'd like to modify the default behaviour please see https://doc.qt.io/qt-5/qt.html#ConnectionType-enum for options available.