QWebEngineView does not show

I have a very simple test project based on QtWebEngine:



#include <QWebEngineView>

class WebengineView : public QWebEngineView

    WebengineView(QWidget *parent = 0);



#include "webengineview.h"

WebengineView::WebengineView(QWidget *parent)
    : QWebEngineView(parent)




#include "webengineview.h"
#include <QApplication>

int main(int argc, char *argv[])

    QApplication a(argc, argv);
    WebengineView w;

    return a.exec();

The only widget is a QWebEngineView object. Unfortunately, after running the program, no window appears to show the web page. And even more weirdly, when I put the  QWebEngineView  object into a layout of another widget, it can display normally. Why does not the QWebEngineView  instance show its own window? Because there are some error messages appearing in the debug console like:

gpu_process_transport_factory.cc(642)] Switching to software compositing.

WARNING:gpu_process_transport_factory.cc(1007)] Lost UI shared context.

I think maybe there is some problem on the graphic card or the display driver. According to this post, I pass the arguments when running the program:

–disable-gpu  –disable-software-rasterizer

But the situation does not change, no window is shown. I had a problem on the incompatible graphic driver, so I add the following line to use software OpenGL,

QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL );

but the problem persists.

In fact, this problem is caused by not setting the size of the window of the QWebEngineView  widget. We have talked about the size of widgets in qt. It seems QWebEngineView widget gets zero size by default so the window is invisible. The solution is very simple, set a size for this QWebEngineView  widget:





If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply