JudgingBird
JudgingBird

Reputation: 61

QWebView always fails to load website

I am running QtCreator 3.2.0, based on Qt 5.3.1 on Windows 8.1.

It seems that no matter what website i am trying to load, the onLoadFinished slot always returns false. I tried to load websites with and without SSL, both failed.

When I tried to load local resources everything worked well. So i monitored my network with wireshark and my Qt application does not even send a request, i also checked the QUrl with QUrl::isValid(), tried to use QWebView::load() instead of QWebView::setUrl() and ran my application as Administrator. Nothing worked.

I can't find any errors in my code and i somewhat feel like this is a bug, but I'm not certain about that.

mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
            this, SLOT(errorcheck(QNetworkReply*)));

    QUrl url("http://www.nasa.gov/");
    ui->webView->setUrl(url);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_webView_loadFinished(bool arg1)
{
    ui->label->setText(arg1 ? "success" : "failure");
}

void MainWindow::errorcheck(QNetworkReply* QNR) {
    qDebug() << QNR->errorString();
}

The output is: "Host www.nasa.gov not found"

Upvotes: 2

Views: 1304

Answers (1)

MKAROL
MKAROL

Reputation: 316

Try

connect(QWebView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(errorcheck(QNetworkReply*)));

void MainWindow::errorcheck(QNetworkReply* QNR) {
qDebug()<<QNR->errorString;
}

And check if any error occure.

Upvotes: 2

Related Questions