QWebEngineView导致的内存性崩溃咋解决?

黄忻 2018-07-20 05:02:39

如图,代码里面是用QPixmap依据路径加载图片,但由于使用了QWebEngineView,结果malloc内存的时候,与QWebEngineView的一个什么_q_destroyed销毁行为发生冲突,搞得头疼不已,谁有遇到过类似的问题么?
下面是demo代码:
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "webmanage.h"
#include "ui_webmanage.h"
#include <QWebChannel>
#include "classroom.h"
#include "global.h"

WebManage::WebManage(QWidget *parent) :
QWidget(parent),
ui(new Ui::WebManage)
{
ui->setupUi(this);

setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(AppTitle);
resize(1200, 714);

m_WebEngineView = new QWebEngineView(this);
m_WebEngineView->setGeometry(rect());
// connect(m_WebEngineView,SIGNAL(urlChanged(QUrl)),this,SLOT(slot_urlChanged(QUrl)));
m_WebEngineView->show();
// m_WebEngineView->load(QUrl("http://www.e2100.cn/PcClient/login.html"));

// m_BtnPageBack = new QPushButton(this);
// m_BtnPageBack->setText("×");
// m_BtnPageBack->setStyleSheet("font: bold 16pt \"宋体\";\ncolor: rgb(62, 177, 52);\nborder: none;");
// m_BtnPageBack->setGeometry(rect().width() - 20,0,20,20);
// connect(m_BtnPageBack,SIGNAL(clicked(bool)),this,SLOT(slot_PageBack()));
// m_BtnPageBack->show();

// m_QtMsgWeb = new QtMsgWeb(this);
// connect(m_QtMsgWeb,SIGNAL(qmw_CloseApp()),this,SLOT(slot_qmw_CloseApp()));
// connect(m_QtMsgWeb,SIGNAL(qmw_enterClassroom(QString)),this,SLOT(slot_qmw_enterClassroom(QString)));
// connect(m_QtMsgWeb,SIGNAL(qmw_minimizeApp()),this,SLOT(slot_qmw_minimizeApp()));

// QWebChannel *wc = new QWebChannel(m_WebEngineView);
// wc->registerObject(QStringLiteral("content"), m_QtMsgWeb);
// m_WebEngineView->page()->setWebChannel(wc);
}

WebManage::~WebManage()
{
delete ui;
}

void WebManage::slot_urlChanged(QUrl url)
{
// if(url.host() == "" || url.host() != "www.e2100.cn")
// return ;

// if(m_ListUrl.count() > 0)
// {
// if(url != m_ListUrl.last())
// m_ListUrl.append(url);
// }
// else
// m_ListUrl.append(url);
}

void WebManage::slot_qmw_CloseApp()
{
// m_QtMsgWeb->disconnect();
// m_QtMsgWeb->deleteLater();
// m_WebEngineView->disconnect();
m_WebEngineView->stop();
m_WebEngineView->close();
// delete m_WebEngineView;
// m_WebEngineView = nullptr;
// m_ListUrl.clear();
close();
}

void WebManage::slot_PageBack()
{
// if(m_ListUrl.count() >= 2)
// {
// m_ListUrl.removeLast();
// m_WebEngineView->load(m_ListUrl.last());
// }
}

void WebManage::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);

slot_qmw_CloseApp();
}

void WebManage::slot_qmw_enterClassroom(QString msg)
{
// hide();

// Classroom *c = new Classroom(nullptr);
// c->initClassroom(msg);
// c->show();
}

void WebManage::slot_qmw_minimizeApp()
{
setWindowState(Qt::WindowMinimized);
}

上面是使用了QWebEngineView的一个Widget,下面是调用的测试块:
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "classroom.h"
#include "ui_classroom.h"
#include "global.h"
#include <QMessageBox>

Classroom::Classroom(QWidget *parent) :
QWidget(parent),
ui(new Ui::Classroom)
{
ui->setupUi(this);

setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(AppTitle);

connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(slot_closeClassroom()));

// Global::g_WebManage = nullptr;
}

Classroom::~Classroom()
{
delete ui;
}

void Classroom::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);

slot_closeClassroom();
}

void Classroom::slot_closeClassroom()
{
close();
}
#include <QDebug>
void Classroom::initClassroom(QString msg)
{
qDebug() << "msg:" << msg;
}
#include "webmanage.h"
void Classroom::on_pushButton_2_clicked()
{
WebManage* we = new WebManage(nullptr);
we->show();
}

void Classroom::on_pushButton_3_clicked()
{
// if(Global::g_WebManage != nullptr)
// {
// Global::g_WebManage = nullptr;
// QMessageBox::question(nullptr,"question","0");
// }
QPixmap *pixmapShared1 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared1->isNull())
QMessageBox::question(nullptr,"question","1");
QPixmap *pixmapShared2 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared2->isNull())
QMessageBox::question(nullptr,"question","2");
QPixmap *pixmapShared3 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared3->isNull())
QMessageBox::question(nullptr,"question","3");
QPixmap *pixmapShared4 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared4->isNull())
QMessageBox::question(nullptr,"question","4");
QPixmap *pixmapShared5 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared5->isNull())
QMessageBox::question(nullptr,"question","5");
QPixmap *pixmapShared6 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared6->isNull())
QMessageBox::question(nullptr,"question","6");
QPixmap *pixmapShared7 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared7->isNull())
QMessageBox::question(nullptr,"question","7");
QPixmap *pixmapShared8 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared8->isNull())
QMessageBox::question(nullptr,"question","8");
QPixmap *pixmapShared9 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared9->isNull())
QMessageBox::question(nullptr,"question","9");
QPixmap *pixmapShared10 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
if(pixmapShared10->isNull())
QMessageBox::question(nullptr,"question","10");
QPixmap *pixmapShared11 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared12 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared13 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared14 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared15 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared16 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared17 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared18 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared19 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
QPixmap *pixmapShared20 = new QPixmap("C:/Users/Administrator/Pictures/11.jpg");
delete pixmapShared1;
pixmapShared1 = nullptr;
delete pixmapShared2;
pixmapShared2 = nullptr;
delete pixmapShared3;
pixmapShared3 = nullptr;
delete pixmapShared4;
pixmapShared4 = nullptr;
delete pixmapShared5;
pixmapShared5 = nullptr;
delete pixmapShared6;
pixmapShared6 = nullptr;
delete pixmapShared7;
pixmapShared7 = nullptr;
delete pixmapShared8;
pixmapShared8 = nullptr;
delete pixmapShared9;
pixmapShared9 = nullptr;
delete pixmapShared10;
pixmapShared10 = nullptr;
delete pixmapShared11;
pixmapShared11 = nullptr;
delete pixmapShared12;
pixmapShared12 = nullptr;
delete pixmapShared13;
pixmapShared13 = nullptr;
delete pixmapShared14;
pixmapShared14 = nullptr;
delete pixmapShared15;
pixmapShared15 = nullptr;
delete pixmapShared16;
pixmapShared16 = nullptr;
delete pixmapShared17;
pixmapShared17 = nullptr;
delete pixmapShared18;
pixmapShared18 = nullptr;
delete pixmapShared19;
pixmapShared19 = nullptr;
delete pixmapShared20;
pixmapShared20 = nullptr;
}

void Classroom::on_pushButton_4_clicked()
{
QDialog* dg = new QDialog(nullptr);
dg->show();
}
...全文
2820 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaobaiqing1983 2019-04-18
  • 打赏
  • 举报
回复
QWebChannel *wc 为成员变量m_wc,在closeEvent或析构中调用QWebChannel::deregisterObject(注册的对象指针)
彩阳 2018-08-08
  • 打赏
  • 举报
回复
问题可能不在WebEngine中,而是你的sharePictureBasic函数可能导致了崩溃现象。模块化你的WebEngine,排除它的干扰。
QtUnremitting 2018-07-27
  • 打赏
  • 举报
回复
仔细检查代码,大多都是自己写错的问题,也可以借助内存泄露检查工具。

21,494

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧