Почему то не скачивает файл с помощью библиотеки QNetworkAccessManager
qt, QNetworkAccessManager, FTP
pesokWidget.pro
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = pesokWidget
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h \
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
w.resize(300, 50);
a.exec();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QLineEdit>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
QLineEdit *edit;
QPushButton *btn;
QNetworkAccessManager *manager;
public:
Widget(QWidget *parent = 0);
~Widget();
public slots:
void onBtn();
void replyFinished();
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include <QVBoxLayout>
#include <QApplication>
#include <QNetworkReply>
#include <QFile>
QStringList needToDounload = {
"ftp://cddis.gsfc.nasa.gov/pub/slr/data/npt_crd/gracea/2010/gracea_20100108.npt.Z",
"ftp://cddis.gsfc.nasa.gov/pub/slr/data/npt_crd/gracea/2010/gracea_20100101.npt.Z"
};
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *mainL = new QVBoxLayout(this);
edit = new QLineEdit();
mainL->addWidget(edit);
btn = new QPushButton("Dounload");
mainL->addWidget(btn);
connect(btn, &QPushButton::clicked, this, &Widget::onBtn);
manager = new QNetworkAccessManager(this);
}
void Widget::onBtn()
{
// берем адрес введенный в текстовое поле
QUrl url(edit->text());
// создаем объект для запроса
QNetworkRequest request(url);
// Выполняем запрос, получаем указатель на объект
// ответственный за ответ
QNetworkReply* reply= manager->get(request);
// Подписываемся на сигнал о готовности загрузки
connect(reply, &QNetworkReply::finished, this, &Widget::replyFinished);
}
void Widget::replyFinished()
{
static int count = 0;
QNetworkReply *reply=
qobject_cast<QNetworkReply *>(sender());
if (reply->error() == QNetworkReply::NoError)
{
// Получаем содержимое ответа
QByteArray content= reply->readAll();
QStringList l = QApplication::arguments().at(0).split("\\");
l.removeLast();
QString fullName = l.join("\\") + QString("\\dounloadFile%1.file").arg(count++);
QFile file(fullName);
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << QString("Could not open %1 for writing: %2")
.arg(fullName).arg(file.errorString());
return;
}
file.write(content);
file.close();
} else {
// Выводим описание ошибки, если она возникает.
qDebug() << reply->errorString();
}
// разрешаем объекту-ответа "удалится"
reply->deleteLater();
}
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 12, 2024, 1:58 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 11:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 11:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
Qt/C++ - Lesson 031. QCustomPlot – The build of charts with time buy generic priligy We can just chat, and we will not lose too much time anyway
Qt/C++ - Lesson 060. Configuring the appearance of the application in runtime I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
Circuit switching and packet data transmission networks Angioedema 1 priligy dapoxetine
How to Copy Files in Linux If only females relatives with DZ offspring were considered these percentages were 23 order priligy online uk
Qt/C++ - Tutorial 068. Hello World using the CMAKE build system in CLion ditropan pristiq dosing With the Yankees leading, 4 3, Rivera jogged in from the bullpen to a standing ovation as he prepared for his final appearance in Chicago buy priligy pakistan
Now discuss on the forum
добавить qlineseries в функции priligy amazon canada 93 GREB1 protein GREB1 AB011147 6
Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
IscanderCheNov. 1, 2024, 1:43 a.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
ИМ
Реализация навигации по разделам Спасибо Евгений!
Игорь МаксимовOct. 3, 2024, 2:05 p.m.
Добрый день!