【问题标题】:QWebPage segmentation faultQWebPage 分段错误
【发布时间】:2014-08-04 13:11:50
【问题描述】:

当我实例化一个 QWebPage 对象时,我遇到了分段错误,我不明白为什么!

我在 main.cpp 中调用我的对象

webview *nav = new webview();

我的 webview.h:

#ifndef WEBVIEW_H
#define WEBVIEW_H

#include <QRegularExpression>
#include <QWebPage>
#include <QWebFrame>
#include <QPrinter>
#include <QDebug>

#include "arguments.h"

class webview
{
public:
    webview();
    ~webview();
    bool load(Arguments *args);
    QWebFrame* getFrame() { return frame;}

private:
    QWebPage *page;
    QWebFrame *frame;
};

还有我的 webview.cpp

#include "webview.h"
webview::webview()
{

    page = new QWebPage();
}
[...]
webview::~webview()
{
delete page;
}

webview 构造函数中出现 Segmentation fault 错误:

page = new QWebPage();

我真的不明白为什么

你可以在这里下载项目:http://www.partage-facile.com/Y8NROQ09HG/htmltopdf.tar.gz.html

【问题讨论】:

标签: c++ qt qwebpage


【解决方案1】:

您不能将 QtWebKit 与 QCoreApplication 一起使用,请将所有 QCoreApplication 更改为 QApplication。

【讨论】:

    【解决方案2】:

    如果你真的不需要将你的页面嵌入到一个小部件中(你没有设置它的 parent)你可以在堆栈上创建 QWebPage。

    See the example in Qt docs

    【讨论】:

    • 我在控制台应用程序上,我不能使用小部件
    • 我的问题是在实例化对象时,文档没有为此提供示例
    • 例子中说要在栈上创建QWebPage
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多