您的位置:首页 > 编程语言 > Qt开发

QT Socket编程过程问题

2017-08-09 10:35 1536 查看
客户端:

[WARNING T10868] 8-9 10:25:35 91 QObject: Cannot create children for a parent that is in a different thread.

(Parent is QTcpSocket(0x23f72c42a40), parent's thread is IpuCommIpu(0x88bd9bfb78), current thread is QThread(0x23f72c250a0)

[WARNING T10868] 8-9 10:25:35 93 QObject: Cannot create children for a parent that is in a different thread.

(Parent is QTcpSocket(0x23f72c42a40), parent's thread is IpuCommIpu(0x88bd9bfb78), current thread is QThread(0x23f72c250a0)

class IPUCOMM_EXPORT IpuComm : public QThread

class IPUCOMM_EXPORT IpuCommIpu : public IpuComm

服务端:

[WARNING T5392] 8-9 10:25:41 573 QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread

[WARNING T5392] 8-9 10:25:41 574 QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread

class IPUCOMM_EXPORT IpuComm : public QThread

class IPUCOMM_EXPORT IpuCommHost : public IpuComm

解决方法:

1、针对IpuCommHost,做如下更改:

IpuCommHost::IpuCommHost(quint16 port)

    : IpuComm()

{

    ///////////////////////// 将IpuCommHost对象,移动到自身对应线程

    this->moveToThread(this);

}

2、针对IpuCommIpu,做如下更改:

IpuCommIpu::IpuCommIpu()

    : IpuComm()

{

    ///////////////////////// 将IpuCommIpu对象,移动到自身对应线程

    this->moveToThread(this);

}

同时,通过IpuCommIpu线程,去调用void QAbstractSocket::connectToHost(const
QHostAddress &address,
quint16
port,
OpenMode
openMode = ReadWrite);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  QT