Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView blank screen
Qt 6.12 LTS is out! See what's new in the release blog

QWebView blank screen

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 13.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N nicholaslee

    0_1531139044328_Forum question.PNG

    I load it in this ui's (timetable) tab.
    It gives me a blank screen.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @nicholaslee What I mean is: where do you execute this line

    ui->webView_2->load(QUrl("https://nusmods.com/timetable/sem-1"));
    

    ?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nicholaslee
      wrote on last edited by
      #7

      It is in my mainwindow.cpp in the function after setupUI

      jsulmJ 1 Reply Last reply
      0
      • N nicholaslee

        It is in my mainwindow.cpp in the function after setupUI

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nicholaslee
          wrote on last edited by
          #9
          #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

          jsulmJ JonBJ 2 Replies Last reply
          0
          • N nicholaslee
            #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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N nicholaslee
              #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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #11

              @nicholaslee
              I don't know but: load https://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?

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nicholaslee
                wrote on last edited by
                #12

                @JonB Yes, I think so, im not totally sure how webview works. How would I load the page if its generated in JavaScript?

                jsulmJ 1 Reply Last reply
                0
                • N nicholaslee

                  @JonB Yes, I think so, im not totally sure how webview works. How would I load the page if its generated in JavaScript?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  @nicholaslee Didn't you say that same page is loading fine when you press the button?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nicholaslee
                    wrote on last edited by
                    #14

                    @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?

                    JonBJ 1 Reply Last reply
                    0
                    • N nicholaslee

                      @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?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #15

                      @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 of ok.

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nicholaslee
                        wrote on last edited by
                        #16
                        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"

                        jsulmJ 1 Reply Last reply
                        0
                        • N nicholaslee
                          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"

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #17

                          @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 do

                          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)
                          {
                          ...
                          }
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2
                          • N Offline
                            N Offline
                            nicholaslee
                            wrote on last edited by
                            #18
                            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!

                            JonBJ 1 Reply Last reply
                            0
                            • N nicholaslee
                              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!

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #19

                              @nicholaslee
                              You need to add qDebug() << ok; there, we need to know what value ok is being passed as.

                              1 Reply Last reply
                              1
                              • N Offline
                                N Offline
                                nicholaslee
                                wrote on last edited by
                                #20

                                The value is passed as a 'true'

                                JonBJ 1 Reply Last reply
                                0
                                • N nicholaslee

                                  The value is passed as a 'true'

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #21

                                  @nicholaslee
                                  Then, fortunately or unfortunately, we've sent you down a wild goose chase, insofar as QWebView confirms that it has successfully completed loading the content. But it's good to know!

                                  Then I can only guess/suggest as per earlier that (assuming you say it is not a https or redirection issue) the web kit is having problems with the JavaScript content? Check the actual content received in the QWebPage/QWebFrame to verify it's what you see in a working browser, and see if there are any signals received indicating it's having problems with the content?

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    agarny
                                    wrote on last edited by
                                    #22

                                    @nicholaslee, you apparently solved your problem (since this is labelled "SOLVED"), but I cannot see what you had to do, if anything, to solve it. Would you mind sharing your findings, if any? (Yes, I am having the same problem with a JavaScript-generated page. I have yet to fully investigate the issue though.)

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt
                                    • Unsolved