How to open the web inspector in QWebView?

4.7k views Asked by At

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.

1

There are 1 answers

5
Klathzazt On BEST ANSWER

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.