qt报错QObject: Cannot create children for a parent that is in a different thread.

问题:
将QTcpSocket封装到一个类,使QTcpSocket的操作在单独一个线程里,在调用connectToHost时,报错:

QObject: Cannot create children for a parent that is in a different thread.

原因:
QTcpSocket类型变量应该定义为指针类型,并且在新线程里执行的函数里创建(new)。

你可能感兴趣的:(Qt,qt)