资源简介
QT5开发源码——聊天工具(MyselfQQ),内部有框架逻辑等全面的功能实现。方便借鉴和学习!
代码片段和文件信息
#include “client.h“
#include “ui_client.h“
#include
#include
#include
Client::Client(QWidget *parent) :
QDialog(parent)
ui(new Ui::Client)
{
ui->setupUi(this);
setFixedSize(400190);
totalBytes = 0;
bytesReceived = 0;
fileNameSize = 0;
tClnt = new QTcpSocket(this);
tPort = 5555;
connect(tClnt SIGNAL(readyRead()) this SLOT(readMsg()));
connect(tClnt SIGNAL(error(QAbstractSocket::SocketError)) thisSLOT(displayerr(QAbstractSocket::SocketError)));
}
Client::~Client()
{
delete ui;
}
void Client::setFileName(QString name)
{
locFile = new QFile(name);
}
void Client::setHostAddr(QHostAddress addr)
{
hostAddr = addr;
newConn();
}
void Client::newConn()
{
blockSize = 0;
tClnt->abort();
tClnt->connectToHost(hostAddr tPort);
time.start();
}
void Client::readMsg()
{
QDataStream in(tClnt);
in.setVersion(QDataStream::Qt_4_7);
float useTime = time.elapsed();
if (bytesReceived <= sizeof(qint64)*2) {
if ((tClnt->bytesAvailable() >= sizeof(qint64)*2) && (fileNameSize == 0))
{
in>>totalBytes>>fileNameSize;
bytesReceived += sizeof(qint64)*2;
}
if((tClnt->bytesAvailable() >= fileNameSize) && (fileNameSize != 0)){
in>>fileName;
bytesReceived +=fileNameSize;
if(!locFile->open(QFile::WriteOnly)){
QMessageBox::warning(thistr(“应用程序“)tr(“无法读取文件 %1:\n%2.“).arg(fileName).arg(locFile->errorString()));
return;
}
} else {
return;
}
}
if (bytesReceived < totalBytes) {
bytesReceived += tClnt->bytesAvailable();
inBlock = tClnt->readAll();
locFile->write(inBlock);
inBlock.resize(0);
}
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(bytesReceived);
double speed = bytesReceived / useTime;
ui->cStatusLbl->setText(tr(“已接收 %1MB (%2MB/s) \n共%3MB 已用时:%4秒\n估计剩余时间:%5秒“)
.arg(bytesReceived / (1024*1024))
.arg(speed*1000/(1024*1024)0‘f‘2)
.arg(totalBytes / (1024 * 1024))
.arg(useTime/10000‘f‘0)
.arg(totalBytes/speed/1000 - useTime/10000‘f‘0));
if(bytesReceived == totalBytes)
{
locFile->close();
tClnt->close();
ui->cStatusLbl->setText(tr(“接收文件 %1 完毕“).arg(fileName));
}
}
void Client::displayerr(QAbstractSocket::SocketError sockErr)
{
switch(sockErr)
{
case QAbstractSocket::RemoteHostClosedError : break;
default : qDebug() << tClnt->errorString();
}
}
void Client::on_cCancleBtn_clicked()
{
tClnt->abort();
if (locFile->isOpen())
loc
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-11-19 11:37 MyselfQQ\
文件 558 2013-07-31 11:02 MyselfQQ\MyselfQQ.pro
文件 18667 2015-11-18 22:12 MyselfQQ\MyselfQQ.pro.user
文件 17707 2013-08-08 10:46 MyselfQQ\MyselfQQ.pro.user.2.7pre1
文件 3297 2013-08-07 16:40 MyselfQQ\client.cpp
文件 934 2013-07-31 16:25 MyselfQQ\client.h
文件 2049 2013-07-31 11:54 MyselfQQ\client.ui
文件 6249 2013-08-01 17:08 MyselfQQ\drawer.cpp
文件 1019 2013-07-24 10:30 MyselfQQ\drawer.h
目录 0 2015-11-19 11:37 MyselfQQ\images\
文件 14164 2013-07-22 16:32 MyselfQQ\images\Cherry.png
文件 47616 2013-07-31 08:45 MyselfQQ\images\Thumbs.db
文件 1611 2013-07-02 09:11 MyselfQQ\images\bold.png
文件 1028 2009-10-16 18:37 MyselfQQ\images\clear.png
文件 960 2009-10-16 18:37 MyselfQQ\images\color.png
文件 13226 2013-07-22 16:31 MyselfQQ\images\dr.png
文件 1164 2013-07-02 10:53 MyselfQQ\images\italic.png
文件 15048 2013-07-22 16:29 MyselfQQ\images\jj.png
文件 14531 2013-07-22 16:29 MyselfQQ\images\lswh.png
文件 12162 2013-07-22 16:31 MyselfQQ\images\qmnn.png
文件 10664 2013-07-22 16:28 MyselfQQ\images\qq.png
文件 1172 2009-10-16 18:37 MyselfQQ\images\save.png
文件 758 2009-09-22 13:43 MyselfQQ\images\send.png
文件 8983 2013-07-22 16:27 MyselfQQ\images\spqy.png
文件 1183 2013-07-02 10:55 MyselfQQ\images\under.png
文件 8426 2013-10-21 17:02 MyselfQQ\images\wy.png
文件 12604 2013-07-22 16:25 MyselfQQ\images\ymrl.png
文件 670 2013-07-23 13:58 MyselfQQ\images.qrc
文件 235 2013-07-22 17:34 MyselfQQ\main.cpp
文件 4107 2013-08-06 17:12 MyselfQQ\server.cpp
文件 974 2013-07-31 16:25 MyselfQQ\server.h
............此处省略4个文件信息
- 上一篇:CAD链接大全
- 下一篇:3GPP_TS_25.331RRC协议中文版.pdf
评论
共有 条评论