why is headless qwebpage throwing sigsegv?

652 views Asked by At

so, I need to parse some javascript against one html page (kinda a scripting for my app), but QWebPage throws SIGSEGV when I try to initialize it. It console application. Relevat parts of my code:

QT       += core sql network xml webkit

QT       -= gui

QMAKE_CXXFLAGS += -std=c++11

LIBS += -lqca

TARGET = jarvisd
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app
QWebPage * p = new QWebPage();
p->mainFrame()->load(QUrl(url));

It crashes on the first line. From documentation for QWebPage, from "Using QWebPage in a Widget-less Environment" part, it seems this should be possible. But there is not error, just sigsegv :/

Thanks for your help.

1

There are 1 answers

1
Davy Jones On

QT += core widgets sql network xml webkit webkitwidgets

Use something like so:

QWebView *view = new QWebView();
view->load(QUrl("http://127.0.0.1"));
QObject::connect(view, &QWebView::loadFinished, [view](){fprintf(stderr, view->title().toLocal8Bit().data());});

etc.

Qt5 signals + lambda function used in the above code.

Edit: The above code runs in console mode on Windows 7. I replaced this snippet with the one in your post. That works too.

Edit 2: OK. I found the reason for the crash. Try replacing QCoreApplication with QApplication. And webkitwigets in the project file is required.