0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QWebEngineView>
#include <qDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
#if 1
    auto btn  = new QPushButton;
    ui->gridLayout->addWidget(btn);
    qDebug()<<btn->winId();
#endif
    auto web = new QWebEngineView;
    ui->gridLayout->addWidget(web);
    web->load(QUrl("http://www.google.com"));
}

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

That's the whole code. Windows 10 , Qt 5.5 .

When I turn on the switch, winId() would be called, then the QtWebEngine can not work rightly.

What should I do ?

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Hunker
  • 97
  • 9

1 Answers1

0

Don't call winId() until the widget is visible. You could set an eventFilter that is activated on QEvent::Show, for further information see http://doc.qt.io/qt-5/qobject.html#installEventFilter

jmagica
  • 73
  • 2
  • 6