Dalamber Dalamber - 1 year ago 376
C++ Question

One QWebEnginePage for two or more QWebEngineView

I have one instance of QWebEnginePage that is loaded with some url (e.g. https://www.google.com)

I want this page to be displayed in two QWebEngineViews, but it looks like Qt doesn't allow that.

Once I call setPage on one view, the other view stops rendering the page.
Looks like it is a matter of ownership or something like that, but I don't see any information about that in Qt docs.

Anyone else faced such issue?

auto p = new QWebEnginePage();

auto w1 = new QWebEngineView();
auto w2 = new QWebEngineView();



I expect both views to display the same page, but only w2 shows it. If you later call
- the page will be displayed on w1 and will disappear from w2.

Joe Joe
Answer Source

Like most classes in Qt, QWebEnginePage is a QObject. QObject always have exactly one parent (owner). The same is true for QWebEnginePage. Furthermore, it has a method QWebEnginePage::view returns a pointer to the QWidget currently showing the page. Therefore, it can by definition only have a single view.

I would suggest creating two QWebEnginePage instances and connecting the signals to their respective slots (or lambdas which call a corresponding non-slot setter) of the other page. Some like scrollPositionChanged might not have corresponding setters, so you might be out of luck for perfect synchronization.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download