Question

I want to open the QWebView web inspector in my application because debugging in QWebView is needed.

How can I do this?


According to the documentation I tried:

view->pageAction(QWebPage::InspectElement)->trigger();

that didn't work, and then I tried this:

view->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

QWebInspector inspector;
inspector.setPage(view->page());
inspector.setVisible(true);

that adds the Inspect element item in the context menu.

How can I show the web inspector from code? I open it using right click -> Inspect element.

I don't want to add it as a widget but as a separate window.

Was it helpful?

Solution

Keep the setAttribute call only. Then you will be able to call the Inspector from the context menu.

The below code is not optimal but it shows how the pieces work together.

To add this to a non-modal dialog:

QDialog dlg;

...

QWebInspector *i = new QWebInspector(this);
dlg.setLayout(new QVBoxLayout());
dlg.layout()->addWidget(i);
dlg.setModal(false);
dlg.show();
dlg.raise();
dlg.activateWindow();

Your QDialog should be a member of the class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top