In the main Widget, I've connected a SIGNAL from QPushButton on the GUI to the SLOT reconnect() from the QThread based class.
Just as below:
connect(ui->pushButton, SIGNAL(released()), udpTest, SLOT(reconnect()), Qt::QueuedConnection);
connect(ui->pushButton, SIGNAL(released()), udpTest, SLOT(reconnect()), Qt::QueuedConnection);
To copy to clipboard, switch view to plain text mode
I made all so simple, as it only was be possible, leaving just the bare minimum, to still work and get the error/warnings.
You can build and run this program.
I added a qDebug() to every operation, so you can read the thread's IDs of any called function.
MainWidget.png
Using netcat one can send some data to the UDP port 1111. Then the debug output should look something like:
Main Loop() thread ID: 0x888
run() thread ID: 0x140c
receive() thread ID: 0x140c
reconnect() thread ID: 0x888
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
QObject: Cannot create children
for a parent that is in a different thread.
(Parent is
QUdpSocket(0x6441a0
), parent
's thread is UDP(0x6448a0), current thread is QThread(0x3193c0)
Main Loop() thread ID: 0x888
run() thread ID: 0x140c
receive() thread ID: 0x140c
reconnect() thread ID: 0x888
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QUdpSocket(0x6441a0), parent's thread is UDP(0x6448a0), current thread is QThread(0x3193c0)
To copy to clipboard, switch view to plain text mode
Bookmarks