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

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

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ftp(NULL),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setValue(0);
connect(ui->fileList,SIGNAL(itemActivated(QTreeWidgetItem*,int)),this,SLOT(processItem(QTreeWidgetItem*,int)));
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_connectButton_clicked()
{
ui->fileList->clear();
currentPath.clear();
isDirectory.clear();
ftp = new QFtp(this);
connect(ftp,SIGNAL(commandStarted(int)),this,SLOT(ftpCommandStarted(int)));
connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(ftpCommandfinished(int,bool)));
connect(ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(addToList(QUrlInfo)));
connect(ftp,SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(updateDataTransferProgress(qint64,qint64)));
QString ftpServer = ui->ftpServerLineEdit->text();
QString userName = ui->userNameLineEdit->text();
QString passWord = ui->passWordLineEdit->text();
ftp->connectToHost(ftpServer,21);
ftp->login(userName,passWord);
}


一连接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)
求帮忙。
...全文
407 6 打赏 收藏 转发到动态 举报
写回复
用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,212

社区成员

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

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