QWebEngineView does not show

I have a very simple test project based on QtWebEngine:

------webengineview.h-------

#ifndef WEBENGINEVIEW_H
#define WEBENGINEVIEW_H

#include <QWebEngineView>

class WebengineView : public QWebEngineView
{
    Q_OBJECT

public:
    WebengineView(QWidget *parent = 0);
    ~WebengineView();
};

#endif // WEBENGINEVIEW_H



-----webengineview.cpp--------------

#include "webengineview.h"

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

WebengineView::~WebengineView()
{

}





-----main.cpp---------

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

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

    QApplication a(argc, argv);
    WebengineView w;
    w.show();
    w.load(QUrl("https://www.google.com"));

    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:

resize(800,600);

 

 

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply