QT 下TCP客户端

//类里声明
QTcpSocket *tcpSocket;
//构造函数里
    tcpSocket = new QTcpSocket(this);
    socket_init();
    connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(readMessage()));
    connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),
            this,SLOT(displayError(QAbstractSocket::SocketError)));
//初始化函数里
void Networkthread::socket_init(void){
    blockSize = 0; //初始化其为0
    tcpSocket->abort(); //取消已有的连接
    tcpSocket->connectToHost("*.*.*.*",6800);
       //连接到主机,这里从界面获取主机地址和端口号
}

 
  

你可能感兴趣的:(QT)