c++ - 不完整类型'class QNetworkReply'的无效使用
问题描述
我在尝试让 HTTP 请求在 QT 中工作时遇到了很多麻烦,我收到了错误:
无效使用不完整类型'class QNetworkReply' QByteArray bts = rep->readAll();
我无法弄清楚,请帮忙,我做错了什么?我对 Qt 的经验为零
这是我的代码:
主窗口.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")));
}
主窗口.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;
};
。轮廓
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
解决方案
这只是意味着你不包括标题:
#include <QNetworkReply>
推荐阅读
- django - 如何将自定义管理器添加到第三方应用程序的模型
- java - 如何覆盖方法?
- asp.net-core - 处理交易错误的最佳方法?
- c++ - C ++中模板类型中的类层次结构
- ruby-on-rails - 为什么我的 FactoryBot 定义看不到我的 lambda 定义(Ruby,Rspec)
- r - r中的logit回归问题
- node.js - 找不到模块'@angular/compiler-cli/ngcc'
- c# - 转到 observablecollection 中的下一个对象时,窗口控件不更新
- session - JSON Web 令牌与会话 - 来自多个设备的身份验证如何详细工作?
- c++ - 将文件放到主目录