怎么使用QFtp对QT5进行编译

发布时间:2021-02-04 15:02:18 作者:Leah
来源:亿速云 阅读:174

本篇文章为大家展示了怎么使用QFtp对QT5进行编译,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

编译

用qtcreator打开qftp/qftp.pro,编译生成库文件。

放入QT5安装目录中

我以Qt5.5.1为例说明,其它版本类似

运行示例项目

CONFIG(debug, debug|release) {
  LIBS += -lQt5Ftpd
} else {
  LIBS += -lQt5Ftp
}

也就是说,ftp的加载方式还不能与Qt5的原生库完全一致,如何做到这一点,我还需要时间研究。

示例项目改进

修正进度条的提前显示,对progressDialog新对象进行如下设置,去掉了取消操作,取消操作有问题,暂时屏蔽。

 progressDialog = new QProgressDialog("download...", nullptr, 0, 100, this);
 progressDialog->setWindowModality(Qt::WindowModal);
 auto winFlags = windowFlags() & ~Qt::WindowMinMaxButtonsHint;
 progressDialog->setWindowFlags(winFlags &~ Qt::WindowCloseButtonHint); //去掉窗口的默认按钮
 progressDialog->reset();          //避免提前显示
 progressDialog->setAutoClose(false);
 progressDialog->setAutoReset(false);

屏蔽取消按钮的消息链接。

//connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));

支持多文件下载
首先,在QTreeWidget生成后,设置其可以选中多行。

fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);

修改downloadFile函数,支持多文件下载。

QList<QTreeWidgetItem*> selectedItemList = fileList->selectedItems();
for (int i = 0; i < selectedItemList.size(); i++)
 {
  QString fileName = selectedItemList[i]->text(0);
  if (QFile::exists(fileName)) {
    QMessageBox::information(this, tr("FTP"),
    tr("There already exists a file called %1 in the current directory.").arg(fileName));
    return;
  }
  file = new QFile(fileName);
  if (!file->open(QIODevice::WriteOnly)) {
    QMessageBox::information(this, tr("FTP"),
    tr("Unable to save the file %1: %2.").arg(fileName).arg(file->errorString()));
    delete file;
    return;
  }
  ftp->get(fileName, file);
  progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
  downloadButton->setEnabled(false);
  progressDialog->exec();
}

项目地址
https://github.com/zhoutk/qtDemo

命令行编译

git clone https://github.com/zhoutk/qtDemo
cd qtDemo/qftp & mkdir build & cd build
cmake ..
cmake --build .

编译时注意:cmake默认为x86架构,需要与你安装的Qt版本对应;编译好了,运行前,请注意目录结构是否正确。

上述内容就是怎么使用QFtp对QT5进行编译,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 对python源码进行编译,加密python脚本
  2. 《CRL Via C#》使用CSC.exe对两个文件进行编译

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

qt5 qftp

上一篇:php怎么控制用户对图片的访问

下一篇:如何在Java中利用栈来反转链表

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》