资源简介
我做的一个TCP文件传输的工具,可以在网络上传输任意大小的文件,最近在学习QT,希望有兴趣的朋友一起交流一下。如果对这个工具的代码有什么建设的发个邮件给我heqiangpc@sohu.com谢谢了。
代码片段和文件信息
#include “dialog.h“
#include “ui_dialog.h“
#include “nfclient.h“
#include
#include
#include
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
ui(new Ui::Dialog)
{
sendBytes = 0;
blockNumber = 0;
maxBytes = 0;
cleanQuit = true;
ui->setupUi(this);
ui->progressBar->setRange(0 1000);
ui->progressBar->setValue(0);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButtonBrow_clicked()
{
ui->lineEditFile->setText(QFileDialog::getOpenFileName(this tr(“Open File“) tr(“.“) tr(“All Files (*)“)));
}
void Dialog::on_pushButtonSend_clicked()
{
cleanQuit = false;
sendBytes = 0;
blockNumber = 0;
maxBytes = 0;
if(ui->lineEditTag->text().isEmpty() || ui->lineEditFile->text().isEmpty())
{
QMessageBox::information(this tr(“Error“) tr(“Tag and File can not be empty.“));
return;
}
ui->pushButtonSend->setEnabled(false);
nfClient* client = new nfClient(this);
connect(client SIGNAL(disconnected()) client SLOT(deleteLater()));
connect(client SIGNAL(disconnected()) this SLOT(on_socketDisconnected()));
connect(client SIGNAL(fileSize(qint64)) this SLOT(setProccessBar(qint64)));
connect(client SIGNAL(bytesWritten(qint64)) this SLOT(updateProccessBar(qint64)));
connect(client SIGNAL(message(QString)) this SLOT(updateStatusLabel(QString)));
connect(client SIGNAL(onerror(qint32)) this SLOT(on_socketError(qint32)));
client->sendFile(ui->lineEditFile->text() ui->lineEditTag->text());
}
void Dialog::updateProccessBar(qint64 v)
{
blockNumber ++;
sendBytes += v;
ui->progressBar->setValue(sendBytes);
qDebug() << “sended number “ << blockNumber << “ cur “ << v << “. “
<< sendBytes << “ bytes. total “ << maxBytes << “ bytes.“;
}
void Dialog::updateStatusLabel(const QString &status)
{
QString st;
st = “Status: “ + status;
ui->labelStatus->setText(st);
}
void Dialog::setProccessBar(qint64 r)
{
maxBytes = r;
ui->progressBar->setRange(0 r-1);
}
void Dialog::on_socketDisconnected()
{
ui->progressBar->setRange(0 100);
ui->progressBar->setValue(100);
ui->pushButtonSend->setEnabled(true);
cleanQuit = true;
}
void Dialog::on_pushButtonQuit_clicked()
{
if(cleanQuit)
close();
else
{
if(QMessageBox::warning(this tr(“Are you sure!“)
tr(“You have file transting.\nAre you sure you want quit?“)
QMessageBox::Ok QMessageBox::Cancel) == QMessageBox::Ok)
close();
}
}
void Dialog::on_socketError(qint32 e)
{
switch(e)
{
case 1:
QMessageBox::warning(this tr(“Error“)
QString::fromUtf8(“目标名错误!\n请输入有效的主机名或IP地址。“)
QMessageBox::Close);
break;
case 2:
QMessageBox::warning(this tr(“Error“)
QString::fromUtf8(“文件名错误!\n请输入有效的文件名及路径。“)
QMessageBox::Close);
break;
case 3:
QMessageBox::warning(this tr(“Error“)
QString::fromUtf8(“连接目标服务器失败!\n请检查网络连接,如果问题依然存在请联系目标服务器管理员。“)
QMessageBox::Close);
}
ui->pushButtonSend->setEnabled(true);
}
- 上一篇:DSP上的指纹识别模块的实现
- 下一篇:数据结构—集合运算实现 实现报告含代码
相关资源
- TCP_UDP对结构体加密数据传输
- Cisco Network Assistant白皮书
- 基于PIC的TCP/IP网络协议和zigbee无线传
- network science Albert-László Barabási
- Ubuntu下操作Excel,qt代码
- Qt图片浏览器 --基于Qt的Graphics View f
- 欧姆龙PLC tcp通信工具
- qtnribbon2破解
- Qt软件开发 完整项目代码
- 欧姆龙以太网通讯TCP/UDP及欧姆龙PLC程
- MQTT_3.1protocol_Specific中文版
- 在QT中使用RTP进行视频的采集和传输
- 流媒体相关协议标准RTP/RTSP/RTCP PDF文档
- Effects of L-type Matching Network on Characte
- 航海模拟器中DCPA TCPA的算法
- TCPMP 支持ce6.0的播放器
- TH upstream-inhibited ARHGAP12 subnetwork for
- Mini6410 Qt4和Qtopia编程开发指南
- TCP/IP协议详解3卷全_高清_带书签
- Qt实现Code39条形码
- qt_ffmpeg_mp4_export_and_import.zip
- QT5.5入门与项目实战
- The evolution and origin of animal Toll-like r
- 计算机网络(第5版)(Computer Networ
- Huffman Compress 霍夫曼编码 压缩 解压缩
- 基于QT的黑白棋游戏设计和实现
- Qt写的连连看小游戏
- QTranslate_6.7.2.7z
- Qt基于FFmpeg播放本地 H.264H264文件
- QT编的MP3播放器
评论
共有 条评论