新手求教,歷程無法使用,在debug的時候在replyfinished函數開始處設置斷點,一直沒有觸發
這是pro文件:
QT += core gui network
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = weatherget
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
這是頭文件:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget parent = 0);
~MainWindow();
private:
void replyFinished(QNetworkReply);
private:
Ui::MainWindow *ui;
QNetworkAccessManager *manager;
};
#endif // MAINWINDOW_H
這是源文件:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QUrl url(QString("http://www.weather.com.cn/adat/sk/101010100.html"));
manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
request.setUrl(url);
manager->get(request);
connect(manager,SIGNAL(finished(QNetworkReply)),this,SLOT(replyFinished(QNetworkReply*)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::replyFinished(QNetworkReply *reply)
{
QTextCodec *codec = QTextCodec::codecForName("utf8");
QString all=codec->toUnicode((reply->readAll()));
ui->textBrowser->setText(all);
reply->deleteLater();
}
知道哪裡錯了,replyfinished函數沒有在h文件裡聲明為publick slots,問題結束