Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Can anyone help-i miss something! filedownloader example
Forum Updated to NodeBB v4.3 + New Features

[Solved] Can anyone help-i miss something! filedownloader example

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    klarsen
    wrote on last edited by
    #1

    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 scope

    i 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_OBJECT

    public:
    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(&#41;;
    

    }@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      [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?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • K Offline
        K Offline
        klarsen
        wrote on last edited by
        #3

        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);@

        1 Reply Last reply
        0
        • K Offline
          K Offline
          klarsen
          wrote on last edited by
          #4

          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 ;)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved