TcpClient::TcpClient(int infoType)//,QObject* parent)//:QObject(parent)
{
typeInfo=infoType;
q=new QSqlQuery();
q->exec("select serverip,serverport from salesiteinfo");
if(q->next())
{
srvIP=q->value(0).toString();
srvPort=q->value(1).toInt();
}
q->clear();
tcpClient=new QTcpSocket();
timer.setInterval(reConInterval);
timer.start();
connect(&timer,SIGNAL(timeout()),this,SLOT(connSrv()));
QObject::connect(tcpClient,SIGNAL(connected()),this,SLOT(sendMsg()));
connect(tcpClient, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(operateError(QAbstractSocket::SocketError)));
//connect(tcpClient,SIGNAL(disconnected()),&timer,SLOT(stop()));
connect(tcpClient,SIGNAL(readyRead()),this,SLOT(recvMsg()));
}
void TcpClient::connSrv()
{
tcpClient->connectToHost(srvIP, srvPort);
//tcpClient->connectToHost(QHostAddress::LocalHost,16689);//测试
timer.stop();
}
void TcpClient::sendMsg()
{
QTextStream sendOut(tcpClient);
if(typeInfo==SEND_DATE)
{
sendOut<<"0001||date checked cmd";
return;
}
......
}
BackThread::BackThread(int socketType)
{
type=socketType;
tcpClient=new TcpClient(type);
}
void BackThread::run()
{
QMutexLocker locker(&mutex);
tcpClient->connSrv();
}
CFindFileForm::CFindFileForm(QWidget* parent):QWidget(parent)
{
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
bt=new BackThread(SEND_DATE);
bt->start();
//tc=new TcpClient(SEND_DATE);
}