问题
When I instantiate an QWebPage object I have a segmentation fault, I don't understand why !
I call my object in main.cpp
webview *nav = new webview();
my 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;
};
and my webview.cpp
#include "webview.h"
webview::webview()
{
page = new QWebPage();
}
[...]
webview::~webview()
{
delete page;
}
An Segmentation fault error appear in webview constructor :
page = new QWebPage();
Really I don't understand why
you can download the project here : http://www.partage-facile.com/Y8NROQ09HG/htmltopdf.tar.gz.html
回答1:
You cannot use QtWebKit with QCoreApplication, change all QCoreApplication to QApplication.
回答2:
if you really don't need to embed you page in a Widget (you don't set the parent of it) you can create the QWebPage on the stack.
See the example in Qt docs
来源:https://stackoverflow.com/questions/25119520/qwebpage-segmentation-fault