QWebView blank screen
-
ui->webView_2->load(QUrl("https://nusmods.com/timetable/sem-1"));
I'm including a webview into my application. All other links works fine except for this one.
Anyone knows why it doesn't show up?
(It is a working website)
Thanks -
ui->webView_2->load(QUrl("https://nusmods.com/timetable/sem-1"));
I'm including a webview into my application. All other links works fine except for this one.
Anyone knows why it doesn't show up?
(It is a working website)
Thanks@nicholaslee Let me guess: all other sites which work are HTTP and not HTTPS?
-
Nope, I just tested it again.
It works from a push button though. But I would want it to load in the window.
-
Nope, I just tested it again.
It works from a push button though. But I would want it to load in the window.
@nicholaslee "But I would want it to load in the window." - what do you mean? Where in your code do you load it?
-
I load it in this ui's (timetable) tab.
It gives me a blank screen. -
I load it in this ui's (timetable) tab.
It gives me a blank screen.@nicholaslee What I mean is: where do you execute this line
ui->webView_2->load(QUrl("https://nusmods.com/timetable/sem-1"));
?
-
It is in my mainwindow.cpp in the function after setupUI
-
It is in my mainwindow.cpp in the function after setupUI
@nicholaslee Can you show the code?
Also, you said it works if you press a buttons: do you execute exactly the same line when the button is pressed? -
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QString> #include <QWebView> #include <QUrl> #include <QDesktopServices> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString link = "https://nusmods.com/timetable/sem-1"; QDesktopServices::openUrl(QUrl(link)); }
Yes, its the same. All other websites work for webview
-
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QString> #include <QWebView> #include <QUrl> #include <QDesktopServices> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString link = "https://nusmods.com/timetable/sem-1"; QDesktopServices::openUrl(QUrl(link)); }
Yes, its the same. All other websites work for webview
@nicholaslee OK, you're loading inside MainWindow constructor - I'm not sure this is the problem as MainWindow is being constructed at that time. You can try to use http://doc.qt.io/qt-5/qtimer.html#singleShot-4 to delay the loading a bit.
-
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QString> #include <QWebView> #include <QUrl> #include <QDesktopServices> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString link = "https://nusmods.com/timetable/sem-1"; QDesktopServices::openUrl(QUrl(link)); }
Yes, its the same. All other websites work for webview
@nicholaslee
I don't know but: loadhttps://nusmods.com/timetable/sem-1
into a web browser and look at the source. The page generated does not contain literal HTML for the view; it's all generated in JavaScript. Is this the root of the problem? -
@JonB Yes, I think so, im not totally sure how webview works. How would I load the page if its generated in JavaScript?
-
@JonB Yes, I think so, im not totally sure how webview works. How would I load the page if its generated in JavaScript?
@nicholaslee Didn't you say that same page is loading fine when you press the button?
-
@jsulm yes the button will open the browser and navigate to the URL.
But webview is just displaying a blank screen. Is there anyway to view it?
-
@jsulm yes the button will open the browser and navigate to the URL.
But webview is just displaying a blank screen. Is there anyway to view it?
@nicholaslee
Put in a slot for http://doc.qt.io/archives/qt-4.8/qwebview.html#loadFinished. Check you do get there, and the value ofok
. -
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); void QWebView::loadFinished(bool ok); }
@JonB sorry im still new to slots, do I just put it in like this?
It's giving me an error "invalid use of qualified-name 'QWebView::loadFinished"
-
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); void QWebView::loadFinished(bool ok); }
@JonB sorry im still new to slots, do I just put it in like this?
It's giving me an error "invalid use of qualified-name 'QWebView::loadFinished"
@nicholaslee said in QWebView blank screen:
void QWebView::loadFinished(bool ok);
This declares a function!
Please read http://doc.qt.io/qt-5/signalsandslots.html
You need to doMainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); connect(ui->webView, &QWebView::loadFinished, this, &MainWindow::handleLoadFinished); } void MainWindow::handleLoadFinished(bool ok) { ... }
-
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); connect(ui->webView, &QWebView::loadFinished, this, &MainWindow::handleLoadFinished); } void MainWindow::handleLoadFinished(bool ok){ qDebug() << QString("Loaded"); }
@jsulm @JonB
Ive put in a slot and yes it prints out loaded but the webview is not showing anything. Btw thanks for the help! -
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString link = "https://nusmods.com/timetable/sem-1"; ui->webView->load(QUrl(link)); connect(ui->webView, &QWebView::loadFinished, this, &MainWindow::handleLoadFinished); } void MainWindow::handleLoadFinished(bool ok){ qDebug() << QString("Loaded"); }
@jsulm @JonB
Ive put in a slot and yes it prints out loaded but the webview is not showing anything. Btw thanks for the help!@nicholaslee
You need to addqDebug() << ok;
there, we need to know what valueok
is being passed as. -
The value is passed as a 'true'