16,211
社区成员
发帖
与我相关
我的任务
分享
void SendThread::running()
{
connectToHost();
while (1)
{
if (m_lstData.empty())
{
QThread::sleep(1);
continue;
}
QString xmlStr = m_lstData.front();
m_lstData.pop_front();
emit send(xmlStr);
m_pNet->getTcpSocket()->write(xmlStr.toUtf8());
}
}
void SendThread::connectToHost()
{
//连接服务器
m_pNet = new NetClient;
m_pNet->connectHost(QString("127.0.0.1"), 9999);
connect(m_pNet->getTcpSocket(), &QTcpSocket::connected,
[]()
{
qDebug() << "服务器已连接";
}
);
connect(m_pNet->getTcpSocket(), &QTcpSocket::disconnected,
[]()
{
qDebug() << "服务器已断开";
}
);
}