How can i get ftp files show on my list widget using QNetworkAccessManager Qt 5.8?
-
What links ?
-
git://code.qt.io/qt/qtftp.git
http://code.qt.io/qt/qtftp.git
https://code.qt.io/qt/qtftp.git -
Those are links to use with the
git clone
command. -
This has nothing to do with Qt.
Didn't you get a new folder named qtftp ?
-
Open the project .pro file with Qt Creator and build it.
By the way, what OS are you on ?
-
Which version of Qt are you using to build that module ?
-
Did you install the module ?
-
Did you add
QT += ftp
to your .pro file and re-run qmake after that ? -
yes.
But commandFinshed signal does not work. here is my code:
FtpDialog.h
#ifndef FTPDIALOG_H
#define FTPDIALOG_H#include <QDialog>
#include <QFtp>
#include <QMessageBox>
#include <QDebug>namespace Ui {
class FtpDialog;
}class FtpDialog : public QDialog
{
Q_OBJECTpublic:
explicit FtpDialog(QWidget *parent = 0);
~FtpDialog();public slots:
void connectClicked();
void ftpFinished(int, bool);
void getFileList();
signals:private:
Ui::FtpDialog *ui;
QFtp ftp;
};#endif // FTPDIALOG_H
-
FtpDialog.cpp
#include "ftpdialog.h"
#include "ui_ftpdialog.h"FtpDialog::FtpDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FtpDialog)
{
ui->setupUi(this);
connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectClicked()));
connect(&ftp,SIGNAL(commandFinished(int,bool)), this, SLOT(ftpFinished(int,bool)));ui->disconnectButton->setEnabled(false); ui->cdButton->setEnabled(false); ui->upButton->setEnabled(false); ui->getButton->setEnabled(false);
}
FtpDialog::~FtpDialog()
{
delete ui;
}void FtpDialog::connectClicked()
{
ui->connectButton->setEnabled(false);ftp.connectToHost("ftp.trolltech.com"); ui->statusLabel->setText(tr("Connecting to host..."));
}
void FtpDialog::ftpFinished(int request, bool error)
{
// Handle errors depending on the command caussing it
qDebug()<<ftp.currentCommand();
if(error)
{
switch(ftp.currentCommand())
{
case QFtp::ConnectToHost:
QMessageBox::warning(this, tr("Error"), tr("Failed to connect to host."));
ui->connectButton->setEnabled(true);break; case QFtp::Login: QMessageBox::warning(this, tr("Error"), tr("Failed to login.")); ui->connectButton->setEnabled(true); break; case QFtp::List: QMessageBox::warning(this, tr("Error"), tr("Failed to get file list.\nClosing connection")); ftp.close(); break; } ui->statusLabel->setText(tr("Ready."));
}
// React to the current command and issue
// more commands or update the user interface
else
{
switch(ftp.currentCommand())
{
case QFtp::ConnectToHost:
ftp.login();break; case QFtp::Login: getFileList(); break; case QFtp::Close: ui->connectButton->setEnabled(true); // getFileList(); break; case QFtp::List: ui->disconnectButton->setEnabled(true); ui->upButton->setEnabled(true); ui->statusLabel->setText(tr("Ready.")); break; } }
}
void FtpDialog::getFileList()
{}
-
@walter-j You should connect a slot to http://doc.qt.io/qt-4.8/qftp.html#stateChanged and see what happens