Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView blank screen
Qt 6.11 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.6k 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 Offline
    N Offline
    nicholaslee
    wrote on last edited by
    #1
    
        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

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

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

      @nicholaslee Let me guess: all other sites which work are HTTP and not HTTPS?

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

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

        Nope, I just tested it again.

        It works from a push button though. But I would want it to load in the window.

        jsulmJ 1 Reply Last reply
        0
        • N nicholaslee

          Nope, I just tested it again.

          It works from a push button though. But I would want it to load in the window.

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

          @nicholaslee "But I would want it to load in the window." - what do you mean? Where in your code do you load it?

          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
            #5

            0_1531139044328_Forum question.PNG

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

            jsulmJ 1 Reply Last reply
            0
            • 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 Online
                        JonBJ Online
                        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 Online
                                JonBJ Online
                                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 Online
                                        JonBJ Online
                                        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

                                          • Login

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