Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to 'QNetworkAccessManager'

Tags:

c++

qt

i'm new to QT API and the QT IDE, i was following this tutorial: http://developer.nokia.com/community/wiki/Creating_an_HTTP_network_request_in_Qt, but when i try to compile i get this errors, the usually cause of the problem is: the compiler couldn't find the .cpp/.lib archive where the code for the methods are, but in this case, the api would be already configured, i can't understand why i'm getting this error, and also i couldn't find the project properties, here is my test code:

#include <QMainWindow>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>

this is the headers included on the mainwindow.hpp file, now the mainwindow.cpp:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QNetworkAccessManager* nam;

    nam = new QNetworkAccessManager(this);
    QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
         this, SLOT(finishedSlot(QNetworkReply*)));

    QUrl url("http://www.forum.nokia.wiki");
    QNetworkReply* reply = nam->get(QNetworkRequest(url));
}

finishedSlot method:

void MainWindow::finishedSlot(QNetworkReply* reply)
{
    //nothing
}

so this is the code, if someone can help i'll thank you :)

like image 695
user2542813 Avatar asked Apr 08 '14 12:04

user2542813


2 Answers

Do you have QT += network in the .pro project file?

Edit: fixed typo, was config instead of QT

like image 200
berkus Avatar answered Oct 13 '22 20:10

berkus


I solved this for CMake by appending following lines to the CMakeLists.txt:

find_package(Qt5Network REQUIRED)
target_link_libraries(${PROJECT_NAME} Qt5::Network)
like image 2
BlueManCZ Avatar answered Oct 13 '22 21:10

BlueManCZ