• 全部
...

QT5使用Qftp使用出现线程错误

gdjoss630 2016-07-03 09:12:49
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"

  3. MainWindow::MainWindow(QWidget *parent) :
  4. QMainWindow(parent),
  5. ftp(NULL),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. ui->progressBar->setValue(0);
  10. connect(ui->fileList,SIGNAL(itemActivated(QTreeWidgetItem*,int)),this,SLOT(processItem(QTreeWidgetItem*,int)));
  11. }

  12. MainWindow::~MainWindow()
  13. {
  14. delete ui;
  15. }

  16. void MainWindow::on_connectButton_clicked()
  17. {
  18. ui->fileList->clear();
  19. currentPath.clear();
  20. isDirectory.clear();
  21. ftp = new QFtp(this);
  22. connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftpCommandStarted(int)));
  23. connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(ftpCommandfinished(int,bool)));
  24. connect(ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(addToList(QUrlInfo)));
  25. connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(updateDataTransferProgress(qint64,qint64)));
  26. QString ftpServer = ui->ftpServerLineEdit->text();
  27. QString userName = ui->userNameLineEdit->text();
  28. QString passWord = ui->passWordLineEdit->text();
  29. ftp->connectToHost(ftpServer,21);
  30. ftp->login(userName,passWord);
  31. }


一连接FTP就出现错误
Cannot create children for a parent that is in a different thread.
(Parent is MainWindow(0x28fe1c), parent's thread is QThread(0x75e338), current thread is QThread(0x7a6b48)
求帮忙。
...全文
给本帖投票
472 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
__网瘾少年 2017-05-10
  • 打赏
  • 举报
回复
问题在哪儿, 我也遇到相同的问题了
gdjoss630 2017-01-05
  • 打赏
  • 举报
回复
引用 4 楼 高高哈哈的回复:
我知道问题在哪,我帮你解决了怎么感谢我啊?
请问怎么解决,谢谢?
高高哈哈 2016-08-23
  • 打赏
  • 举报
回复
我知道问题在哪,我帮你解决了怎么感谢我啊?
gdjoss630 2016-07-08
  • 打赏
  • 举报
回复
没解决问题,不知道是哪里出错了,直接从光盘里考例子出来又行了。代码一一比对过没发现哪里出错...
Little柯南 2016-07-04
  • 打赏
  • 举报
回复
第一,一般而言,new分配内存空间最好是一个初始化过程,所以建议将 ftp = new QFtp(this);写在构造函数里,就是你的MainWindow::MainWindow(QWidget *parent) 这里面,这在哪一般都不会错; 第二,Qt4给予ftp的初始化: QFtp ( QObject * parent = 0 ),你的提示是this,即默认以你的mainwindow作为了他的父对象,这里建议你换成 ftp = new QFtp(0);试试
冷静忍耐 2016-07-04
  • 打赏
  • 举报
回复
ftp = new QFtp(this); 写构造函数试一下??

16,816

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部