QT 简单QNetwork历程无法使用

新手求教,历程无法使用,在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();
}

查看全部
u011094358
qwzlh
2015/06/03 03:13
  • qt5
  • qt
  • ui
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复