Nominate our 2022 Qt Champions!

[SOLVED] Get remote web code

  • hello everyone ..
    I would pick up the HTML code for a page remotely. this is my code and related errors.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QtNetwork/QtNetwork"

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
         connect(manager, SIGNAL(finished(QNetworkReply*)),
                 this, SLOT(replyFinished(QNetworkReply*)));


    mainwindow.cpp:11: error: undefined reference to QNetworkAccessManager::QNetworkAccessManager(QObject*)' mainwindow.cpp:15: error: undefined reference toQNetworkRequest::QNetworkRequest(QUrl const&)'
    mainwindow.cpp:15: error: undefined reference to QNetworkAccessManager::get(QNetworkRequest const&)' mainwindow.cpp:15: error: undefined reference toQNetworkRequest::~QNetworkRequest()'

  • Lifetime Qt Champion


    Did you added

    @QT += network@

    To your pro file ?

    Though it should be in by default IIRC

  • no, I have not added. in which files should be placed? and in what position? thank you.

  • It needs to be added to your project file which is named after your project and has .pro as filename extension.

  • thanks a lot, now runs without errors.
    in the bottom of the document I added this slot:
    void MainWindow::replyFinished(QNetworkReply *pReply)
    QByteArray data=pReply->readAll();
    QString str(data);
    qWarning() << str;

    but in the application otput not see anything, only ""
    then enters into the slot but does not read anything.

  • I tried it on another pc and it works , thanks a lot to everyone.

Log in to reply