技术专栏
Qt混合式开发—网页调试
Qt混合式开发—网页调试
Qt混合式开发时有些问题需要在运行环境下才会出现,这时候就需要在app上调试网页,qt就提供了调试网页的方法,下面就是调出调试窗口的方法:
//调试界面的实现
#ifndef INSPECTOR_H
#define INSPECTOR_H
#include <QQuickItem>
#include <QDialog>
#include <QPushButton>
#include <QWebEngineView>
#include <QStackedLayout>
class Inspector : public QDialog
{
public:
Inspector(QWebEnginePage *source,QWidget *parent = nullptr);
private:
QWebEngineView* m_webView = nullptr;
protected:
void closeEvent(QCloseEvent *event);
};
#endif // INSPECTOR_H
#include "inspector.h"
Inspector::Inspector(QWebEnginePage *source, QWidget *parent):QDialog(parent)
{
resize(1500,800);
m_webView = new QWebEngineView(this);
source->setDevToolsPage(m_webView->page());
source->triggerAction(QWebEnginePage::InspectElement);
QStackedLayout* layout = new QStackedLayout(this);
this->setLayout(layout);
layout->addWidget(m_webView);
QDialog::show();
}
void Inspector::closeEvent(QCloseEvent *)
{
this->accept();
delete m_webView;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
<
实现网页右击弹出菜单选项,点击调试按钮弹出调试窗口
class QWebview : public QWebEngineView
{
Q_OBJECT
public:
QWebview(QString sUrl,QWidget *parent = nullptr);
~QWebview() override;
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
};
void QWebview::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = page()->createStandardContextMenu();
const QList<QAction *> actions = menu->actions();
auto inspectElement = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement));
if (inspectElement == actions.cend()) {
auto viewSource = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::ViewSource));
if (viewSource == actions.cend())
menu->addSeparator();
QAction *action = new QAction(menu);
action->setText("Open inspector in new window");
QAction *before(inspectElement == actions.cend() ? nullptr : *inspectElement);
menu->insertAction(before, action);
connect(action, &QAction::triggered,this,[this](){new Inspector(page());});
} else {
(*inspectElement)->setDisabled(true);
}
menu->popup(event->globalPos());
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
<
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
1
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包

相关专栏
-
浏览量:4693次2020-09-13 21:35:31
-
浏览量:2018次2023-04-19 09:06:21
-
浏览量:2702次2020-12-31 09:42:35
-
浏览量:1657次2020-06-24 16:06:58
-
浏览量:1881次2020-03-26 09:22:01
-
浏览量:3372次2020-08-22 16:09:02
-
浏览量:1168次2023-08-28 09:05:19
-
浏览量:2105次2019-06-05 09:23:47
-
浏览量:4129次2020-10-31 13:45:39
-
浏览量:12354次2020-08-23 21:54:03
-
浏览量:1974次2019-11-21 09:02:10
-
浏览量:1206次2021-01-30 10:45:10
-
浏览量:5145次2020-12-16 11:40:58
-
浏览量:9605次2020-08-18 20:20:36
-
浏览量:24750次2022-03-17 09:00:48
-
浏览量:2337次2020-12-18 10:11:16
-
浏览量:846次2023-07-26 10:00:21
-
浏览量:3681次2020-12-05 13:04:57
-
浏览量:2120次2020-12-01 10:12:12
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者

小王子🤴
您的支持将鼓励我继续创作!
打赏金额:
¥1

¥5

¥10

¥50

¥100

支付方式:

举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注