I am trying to make a basic program with the QNetworkAccessManager but I cannot create an instance of the QNetworkAccessManager class. In my header file I instanitate it but then I get a host of errors (8 of them) in the constructor and destructor functions when look similar to the following:
in function MainWindow:
undefined reference to '_imp__ZN21QNetworkAccessManagerC1EP7QObject' mainwindow.cpp 6
Here is the header file code
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUrl>
#include <QFile>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QtNetwork>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void downloadfile();
private:
Ui::MainWindow *ui;
QNetworkAccessManager manager;
QNetworkReply *reply;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUrl>
#include <QFile>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QtNetwork>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void downloadfile();
private:
Ui::MainWindow *ui;
QUrl url;
QNetworkAccessManager manager;
QNetworkReply *reply;
QFile *file;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
source code
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::downloadfile(){
url = ui->lineEdit->text();
reply = manager.get(QNetworkRequest(url));
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::downloadfile(){
url = ui->lineEdit->text();
reply = manager.get(QNetworkRequest(url));
}
To copy to clipboard, switch view to plain text mode
Thanks for your help in advance
Bookmarks