MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); pixb.load(":/black.png"); pixw.load(":/white.png"); connected = false;//还没有连接 beconnected = false; exchange = true; //link = 1; //numw = 0; //connect(mConnectBtn, SIGNAL(clicked()), this, SLOT(on_pushButton_6_clicked())); //TCP客户端槽函数 connect(&tcpClient, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(dispalyError(QAbstractSocket::SocketError)));//检查错误 connect(&tcpClient, SIGNAL(readyRead()), this, SLOT(client_readMessage())); //TCP服务器槽函数 connect(&tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); //监听 if(!tcpServer.isListening() && !tcpServer.listen(QHostAddress::Any, 6665)) { qDebug() << tcpServer.errorString(); close(); } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); tcpSocket=new QTcpSocket(this); connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(readMessage())); connect(tcpSocket,SIGNAL(error(QAbstractSocker::SocketError)),this,SLOT(dispalyError(QAbstractSocket::SocketError))); }