1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "mythread.h"
- MyThread::MyThread(QObject *parent): QThread(parent)
- {
- }
- void MyThread::MyThread::run()
- {
-
- printf("this is MyThread");
- qDebug() << "this is MyThread begin:" << QThread::currentThreadId();
-
- QTcpServer* server=new QTcpServer(this);
-
- bool res=server->listen(QHostAddress::Any,8018);
- qDebug() << "this is listen ret:" << res;
-
- connect(server,&QTcpServer::newConnection,[=]()
- {
- QTcpSocket* tcpSocket=server->nextPendingConnection();
- qDebug() << "this is listen tcpSocket:" << tcpSocket;
-
-
- connect(tcpSocket,&QTcpSocket::readyRead,[=]()
- {
-
- auto sMsg=tcpSocket->readAll();
- qDebug()<<"Datas from the remote client:"<<sMsg;
- });
-
- QByteArray sWriteMsg="Hello Client";
- tcpSocket->write(sWriteMsg);
- });
- qDebug() << "this is MyThread end:" << QThread::currentThreadId();
-
- }
|