查看完整版本: [--
Qt TCP在线程中连接后数据发送不了
--]
QTCN开发网
->
Qt基础编程
->
Qt TCP在线程中连接后数据发送不了
[打印本页]
登录
->
注册
->
回复主题
->
发表主题
luanl
2017-06-13 13:42
Qt TCP在线程中连接后数据发送不了
在弄Qt TCP客户端部分,在QT中出创建一个线程,用于TCP断线能够重连,
但是发现数据发送不出去,不知道为什么?还请大神指点迷津?
1、如果要想发送数据,只能server端先发送一个数据给Client端,这时clent端数据却能正常发送。
2、当关闭程序后,数据又一次性的发送到server端,数据应该阻塞在这?怎么能发送立马发出去呢。如图:
[attachment=17266]
m_MutexOperate.lock();
if (!m_isOkConect)
{
connect(TcpSocket, SIGNAL(readyRead()), this, SLOT(ReceiveData()));
connect(TcpSocket, SIGNAL(connected()), this, SLOT(Onconnect()));
connect(TcpSocket, SIGNAL(disconnected()), this, SLOT(OnDisConnect()));
}
if (!m_isOkConect)
{
TcpSocket->connectToHost(IP, Port);
m_isOkConect = TcpSocket->waitForConnected(30);
ParamManage::GetSingleTon()->m_pTcpIPCom.TcpConnectionState = m_isOkConect;
TcpSocket->waitForReadyRead(30);//延时
}
sendData("123",3);
m_MutexOperate.unlock();
bran_lee
2017-06-14 11:52
你的sendData又是如何实现的呢
lichen221334
2017-06-14 17:44
1.使用work - object 的方式驱动线程
2. 使用 moveToThread 方法将 Socket 移动到线程中
luanl
2017-06-15 19:35
lichen221334
:
1.使用work - object 的方式驱动线程
2. 使用 moveToThread 方法将 Socket 移动到线程中
(2017-06-14 17:44)
非常感谢
查看完整版本: [--
Qt TCP在线程中连接后数据发送不了
--] [--
top
--]
Powered by
phpwind
v8.7
Code ©2003-2011
phpwind
Gzip disabled