invalid use of incomplete type ‘class QNetworkReply’

487 Views Asked by At

I'm having a lot of trouble trying to get an HTTP request to work in QT, I'm getting the error:

invalid use of incomplete type ‘class QNetworkReply’ QByteArray bts = rep->readAll();

and I can't figure it out, please help, what am I doing wrong? I have zero experience with Qt

here's my code:

mainwindow.cpp

void MainWindow::onfinish(QNetworkReply *rep)
{
    QByteArray bts = rep->readAll();
    QString str(bts);
    QMessageBox::information(this,"sal",str,"ok");

}

void MainWindow::getAPI()
{
    {
        QNetworkAccessManager * mgr = new QNetworkAccessManager(this);
        connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(onfinish(QNetworkReply*)));
        connect(mgr,SIGNAL(finished(QNetworkReply*)),mgr,SLOT(deleteLater()));

        mgr->get(QNetworkRequest(QUrl("http://www.google.com")));

}

mainwindow.h

class MainWindow;
}

class MainWindow : public QMainWindow
{
 Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void UpdateTime();
    void getAPI();
    void onfinish(QNetworkReply *rep);


private:
    Ui::MainWindow *ui;
    QTimer *timer_1s;

};

.pro file

QT       += core gui
QT       += core gui widgets network printsupport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = ApiRequest
TEMPLATE = app


DEFINES += QT_DEPRECATED_WARNINGS

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui
                 
1

There are 1 best solutions below

0
On

That just means you're not including the header:

#include <QNetworkReply>