The only way to enable threading demonstrated in qt documentation is through inheriting QThread and then override its run() method.
class MyThread : public QThread
{
public:
void run();
};
void MyThread::run()
{
QTcpSocket socket;
// connect QTcpSocket's signals somewhere meaningful
...
socket.connectToHost(hostName, portNumber);
exec();
}
I wonder if there is any way to use qt thread without ever inheriting from any qt objects?
You can use multithreading without inheriting from QObject with QtConcurrent::run():
QFuture QtConcurrent::run ( Function function, ... )
Runs function in a separate thread. The thread is taken from the global QThreadPool. Note that the function may not run immediately; the function will only be run when a thread is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With