How can i get ftp files show on my list widget using QNetworkAccessManager Qt 5.8?
-
Dear Freinds,
Im writing a small ftp program that can connect to ftp.trolltech.com and list all files on a list widgets and download it. i can connect to ftp.trolltech.com but i don't know how to list them . Please help me im new in Qt programming.
Thank you for your support.
-
FtpDialog.h
#ifndef FTPDIALOG_H
#define FTPDIALOG_H#include <QDialog>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <QDebug>namespace Ui {
class FtpDialog;
}class FtpDialog : public QDialog
{
Q_OBJECTpublic:
explicit FtpDialog(QWidget *parent = 0);
~FtpDialog();public slots:
void connectClicked();
void readRead(QNetworkReply *reply);
void getFiles(QNetworkReply *reply);
signals:
void dataReadyRead(QByteArray);private:
Ui::FtpDialog *ui;
QNetworkAccessManager *ftp = new QNetworkAccessManager(this);
};#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(finished(QNetworkReply )), this, SLOT(readRead(QNetworkReply )));
connect(ftp, SIGNAL(finished(QNetworkReply)), this, SLOT(getFiles(QNetworkReply)));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->get(QNetworkRequest(QUrl("ftp.trolltech.com"))); ui->statusLabel->setText(tr("Connecting to host..."));
}
void FtpDialog::readRead(QNetworkReply *reply)
{
ui->statusLabel->setText(tr("Ready."));ui->disconnectButton->setEnabled(true); ui->cdButton->setEnabled(true); ui->upButton->setEnabled(true); ui->getButton->setEnabled(true);
}
void FtpDialog::getFiles(QNetworkReply *reply)
{QByteArray data = reply->readAll(); qDebug()<< data;
}
-
Hi,
The old QFtp module might make your life easier.
-
But Qt Creator does not recognize it. what can i do please?
-
Clone it and build it.
-
those links gave me a 404 error. sorry
-
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. -
please be patient with me im new in Qt. i have typed git clone git://code.qt.io/qt/qtftp.git. i have this message checking connectivity....done. what can i do else?
-
This has nothing to do with Qt.
Didn't you get a new folder named qtftp ?
-
yes . will i build it in Qt?
-
Open the project .pro file with Qt Creator and build it.
By the way, what OS are you on ?
-
linux mint 18 sarah
-
i got this message : cannot create a directory / mkspecs/modules-inst when im building it
-
Which version of Qt are you using to build that module ?
-
Qt 5.7.1 . now i can build . what can i do else?
-
my programm does not recognize QFtp but i have already built it
-
Did you install the module ?
7/41