CodeLibrary/05_QtCreator_Cplus_TCPServer_20240423/thread.cpp

27 lines
454 B
C++
Raw Normal View History

#include "thread.h"
Thread::Thread(QTcpSocket *s)
{
isStop = false;
socket = s;
}
void Thread::myTimeout(){
while (!isStop){
connect(socket, &QTcpSocket::readyRead, this, &Thread::clientInfoSlots);
if (isStop){
break;
}
}
}
void Thread::clientInfoSlots(){
QByteArray ba = socket->readAll();
// 发送信号
emit sendToWidget(ba);
}
void Thread::setFlag(bool flag){
isStop = flag;
}