我有一个 Qt(QObject) 类,当声明时,应用程序会在初始化后立即崩溃或在 GUI 显示后几秒钟崩溃。
这个类就是这样的:
webPage.h
class webPage : public QWebPage
{
Q_OBJECT
public:
webPage(QObject *parent = 0);
~webPage();
};
webPage.cpp
webPage::webPage(QObject *parent)
: QWebPage(parent)
{
qDebug() << "webPage::webPage() got called!";
}
webPage::~webPage()
{
}
还有我的mainwindow.h类:
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *e);
private slots:
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
public:
Ui::MainWindow *ui;
browserControl webControl;
webPage page; // <-- unless I remove this, the application crashs.
};
构造函数是这样的:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//webControl.setPage(&page);
}
谁能帮我指出错误原因?它甚至不是 SEGFAULT 之类的,以 Debug模式启动没有帮助,应用程序崩溃/卡住。
最佳答案
完全来自 webkitwidgets documentation :
由于 WebKit 引擎的大小,在许多平台上使用调试符号构建 Qt WebKit 模块是有问题的。我们建议仅在嵌入式平台的 Release模式下构建模块。当前,使用 gcc 时,Qt WebKit 将始终在没有调试符号的情况下进行编译。如果您需要更改它,请查看 Tools/mkspecs/features/production_build.prf。
对应于这个BUG QTBUG-44108 ... Qt WebEngine 仅在 Windows 上的 MSVS 2013 包中可用。 MinGW 和以前的 Visual Studio 版本目前无法使用,因此您需要 Visual Studio 2013 或 Visual Studio 2013 Express Edition
此外,一些有经验的人建议做 Porting from Qt WebKit to Qt WebEngine
关于c++ - 没有运行时错误不能从网页类继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48358616/