[Solved] Can anyone help-i miss something! filedownloader example
-
Hey is there someone how has experince i web filedownload
i have created a standard mainboard in qt-creator. and suplied it with the example filedownloader from
"http://developer.qt.nokia.com/wiki/Download_Data_from_URL"and added the few things shown last in the example. But i get following message.
In constructor ‘MainWindow::MainWindow(QWidget*)’:
mainwindow.cpp 13: error: ‘m_pImgCtrl’ was not declared in this scopei have thoose files, but i don't get why m_pImgctrl not is set ass anything!
in filedownloader.h
@#ifndef FILEDOWNLOADER_H
#define FILEDOWNLOADER_H
#include <QObject>
#include <QByteArray>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
class FileDownloader : public QObject
{
Q_OBJECT
public:
explicit FileDownloader(QUrl imageUrl, QObject parent = 0);
virtual ~FileDownloader();
QByteArray downloadedData() const;
signals:
void downloaded();
private slots:
void fileDownloaded(QNetworkReply pReply);
private:
QNetworkAccessManager m_WebCtrl;
QByteArray m_DownloadedData;
};
#endif // FILEDOWNLOADER_H@in filedownloader.cpp
@#include "filedownloader.h"FileDownloader::FileDownloader(QUrl imageUrl, QObject parent) :
QObject(parent)
{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply)),
SLOT(fileDownloaded(QNetworkReply*)));
QNetworkRequest request(imageUrl);
m_WebCtrl.get(request);
}FileDownloader::~FileDownloader()
{
}void FileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
//emit a signal
emit downloaded();
}QByteArray FileDownloader::downloadedData() const
{
return m_DownloadedData;
}
@in mainwindow.h
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
Ui::MainWindow *ui;private slots:
void loadImage();
};
#endif // MAINWINDOW_H
@in mainwindow.cpp
@#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "filedownloader.h"
#include "QUrl"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);QUrl imageUrl("http://qt.nokia.com/logo.png"); m_pImgCtrl = new FileDownloader(imageUrl, this); connect(m_pImgCtrl, SIGNAL(downloaded()), SLOT(loadImage()));
}
In constructor ‘MainWindow::MainWindow(QWidget*)’:
13: error: ‘m_pImgCtrl’ was not declared in this scope
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::loadImage()
{
QPixmap buttonImage;
buttonImage.loadFromData(m_pImgCtrl->downloadedData());
}
@and last main.cpp
@#include <QtGui/QApplication>
#include "mainwindow.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}@
-
[quote]
In constructor ‘MainWindow::MainWindow(QWidget*)’:
mainwindow.cpp 13: error: ‘m_pImgCtrl’ was not declared in this scope
[/quote]Where is that variable declared then?
-
I don't get it, in one way i see the same thing, that m_pImgCtrl is not declared in my mainwindow.
but this line @m_pImgCtrl = new FileDownloader(imageUrl, this);@
i mayby not understand whats going on there
because when i look i main.cpp i use this
@MainWindow w;
w.show();@but i don't get what i have to declare m_pImgCtrl ass
i tried i out with
@QbyteArray m_pImgCtrl; @
and then use the line @m_pImgCtrl = new FileDownloader(imageUrl, this);@ -
Tank you for a quick answer peppe.
@m_lblImage = new QLabel(centralWidget);@ @ m_lblImage->setObjectName(QString::fromUtf8("m_lblImage"));@
i forgot to declare something thats right, i looked and looked, but i think it was to late, and after some
sleep i found it. i have written @m_ilblImage = new QLabel(centralWidget);@
and that dons't work out ;)