在qt文档中展示线程的唯一方法是继承QThread,然后覆盖它的run()方法。是否可以使用Qt线程而不继承任何Qt对象?
class MyThread : public QThread
{
public:
void run();
};
void MyThread::run()
{
QTcpSocket socket;
// connect QTcpSocket's signals somewhere meaningful
...
socket.connectToHost(hostName, portNumber);
exec();
}
我不知道是否有任何方式使用qt线程,而不从任何qt对象继承?
Qt文档和答案已过时。 Qt强烈鼓励现在使用QThread的另一种方式:http://doc.qt.io/qt-5/qthread.html – ymoreau 2017-08-23 14:18:07