0 Star 0 Fork 3

fujingyuan/AutoVehTypeMon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myclient.cpp 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
惊险一血 提交于 2014-10-28 10:39 . 首次提交
#include "myclient.h"
#include <QHostAddress>
#include "mytask.h"
MyClient::MyClient(QObject *parent) :
QObject(parent)
{
QThreadPool::globalInstance()->setMaxThreadCount(20);
//mytask = NULL;
socket = NULL;
}
void MyClient::SetSocket(int Descriptor)
{
socket = new QTcpSocket();
//socket = sock;
socket->setSocketDescriptor(Descriptor);
connect(socket,SIGNAL(connected()),this,SLOT(comeconnected()));
connect(socket,SIGNAL(disconnected()),this,SLOT(newdisconnected()));
connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
QString str = QObject::tr("hello : %1:").arg(Descriptor);
socket->write(str.toLocal8Bit());
socket->flush();
socket->waitForBytesWritten(10);
}
void MyClient::comeconnected()
{
qDebug()<<"client connected event";
}
void MyClient::newdisconnected()
{
qDebug()<<"client disconnected event";
}
void MyClient::readyRead()
{
QString ip = socket->peerAddress().toString();
qDebug()<<ip+":"+socket->readAll();
MyTask* mytask = new MyTask();
mytask->setAutoDelete(true);
connect(mytask,SIGNAL(Result(int)),this,SLOT(TaskResult(int)),Qt::DirectConnection);
QThreadPool *pool = QThreadPool::globalInstance();
pool->start(mytask);
qDebug()<<"active thread count:"<<pool->activeThreadCount();
}
void MyClient::TaskResult(int Number)
{
// QByteArray Buffer;
// Buffer.append("Result = ");
// Buffer.append(QString::number(Number));
// socket->write(Buffer);
// socket->waitForBytesWritten(30000);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fujingyuan/AutoVehTypeMon.git
git@gitee.com:fujingyuan/AutoVehTypeMon.git
fujingyuan
AutoVehTypeMon
AutoVehTypeMon
master

搜索帮助