資源簡介
關于QT多線程子線程使用信號和槽,再主線程最后必須調用exit()和wait()函數

代碼片段和文件信息
#include?“qsysendthread.h“
QSYSendThread::QSYSendThread(Qobject?*parent)?:?QThread(parent)
{
}
void?QSYSendThread::run()
{
????m_conectIP?=?g_EnvVariant.m_conectToIp;
????m_connectPort?=?g_EnvVariant.m_conectToPort;
????m_client?=?new?QTcpSocket();
????m_client->connectToHost(m_conectIPm_connectPort);
????connect(m_clientQTcpSocket::disconnectedthisQSYSendThread::ClientClosedQt::DirectConnection);
????connect(m_clientQTcpSocket::readyReadthisQSYSendThread::ClientClosedQt::DirectConnection);
????if(m_client->state()==QAbstractSocket::ConnectedState)
????{
????????cout<<“connnect?to?server?fail?!!!?“;
????}
????else
????{
????????cout<<“connnect?to?server?successful?!!!?“;
????}
????m_pTimer?=?new?QTimer();
????m_pTimer->start(2000);
????connect(m_pTimerQTimer::timeoutthisQSYSendThread::TimeOutQt::DirectConnection);
????exec();
????delete?m_client;
????delete?m_pTimer;
}
void?QSYSendThread::ClientClosed()
{
????cout<<“server?is?closed?!!!?“;
}
void?QSYSendThread::ClientError(QAbstractSocket::SocketError?/*socketError*/)
{
}
void?QSYSendThread::TimeOut()
{
????if(m_client->state()==QAbstractSocket::UnconnectedState)
????{
????????m_client->connectToHost(m_conectIPm_connectPort);
????????cout<<“connnect?to?server??!!!?“;
????}
????cout<<“timeout!!?“;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????578??2018-01-03?09:59??qsysendthread.h
?????文件????????1334??2018-01-03?10:54??qsysendthread.cpp
- 上一篇:excle打開nc文件插件
- 下一篇:MSP430F5529_ADC12模塊程序
評論
共有 條評論