richbai90
richbai90

Reputation: 5204

Nothing renders in my QT application -- just a blank screen

I'm following the documentation for the WebEngineView in QT and I can't get this simple example to work. I've included an image of the layout for context. This all builds without errors, but when the form loads there's nothing there.

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow),
      instructionView(new QWebEngineView(this)) {
    ui->setupUi(this);
    ui->p1Instructions->addWidget(instructionView);
    instructionView->load(QUrl("http://qt-project.org/"));
    instructionView->show();
}

This is the layout I'm trying to add the WebEngineView to

enter image description here

This is what I get when I run the program

enter image description here

Upvotes: 1

Views: 831

Answers (1)

richbai90
richbai90

Reputation: 5204

Turns out it wasn't a WebEngine problem at all, it was a problem of not being aware of some of the 'automagical' things that QT does behind the scenes. I renamed the centralwidget to root. Renaming it back to centralwidget fixed the problem.

I could probably also have set the central widget in the constructor like so (note :

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow),
      instructionView(new QWebEngineView(this)) {
    ui->setupUi(this);
    // Set the central widget so QT knows what to display
    setCentralWidget(ui->root);
    ui->p1Instructions->addWidget(instructionView);
    instructionView->load(QUrl("http://qt-project.org/"));
    instructionView->show();
}
``

Upvotes: 1

Related Questions