...
header
...
...
...
source
...
void TCP::run()
{
initSocket();
}
void TCP::initSocket()
{
for(int i=0;i<2;i++)
{
connect(socket[i], SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
connect(socket[i], SIGNAL(connected()),this, SLOT(connected()), Qt::DirectConnection);
connect(socket[i], SIGNAL(disconnected()),this, SLOT(stopConnection()), Qt::DirectConnection);
connect(socket[i], SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
startConnection(i);
}
exec();
}
void TCP::startConnection(int conNUM)
{
socket[conNUM]->connectToHost(addr, port[conNUM]);
}
.....
...
header
...
QTcpSocket *socket[10];
...
...
source
...
void TCP::run()
{
initSocket();
}
void TCP::initSocket()
{
for(int i=0;i<2;i++)
{
socket[i] = new QTcpSocket();
connect(socket[i], SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
connect(socket[i], SIGNAL(connected()),this, SLOT(connected()), Qt::DirectConnection);
connect(socket[i], SIGNAL(disconnected()),this, SLOT(stopConnection()), Qt::DirectConnection);
connect(socket[i], SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
startConnection(i);
}
exec();
}
void TCP::startConnection(int conNUM)
{
QHostAddress addr(address[conNUM]);
socket[conNUM]->connectToHost(addr, port[conNUM]);
}
.....
To copy to clipboard, switch view to plain text mode
Bookmarks