Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtWebkit: console application

I am new to Qt.

I am building a console application and I need to process lot of real world html pages. QtWebkit comes as an easy choice because of clearly cut APIs and easy availability.

I checked out the docs and they say that I can load pages by using QWebView::load(). But I am building a console application and I cannot use a widget. I get the error as: ?

QWidget: Cannot create a QWidget when no GUI is being used
The program has unexpectedly finished.

So how can I process the html pages using QtWebkit in console application.

like image 306
Xolve Avatar asked Aug 20 '10 03:08

Xolve


2 Answers

QtWebkit can be used in a widget-less environment, but can't be executed with QCoreApplication.

The solution is to use a fake X server to execute the program.

Install Xvfb and then:

xvfb-run --server-args="-screen 0 1024x768x24" ./framecapture google.cat google.png

PD: Using framecapture Webkit example from docs: http://doc.qt.io/archives/qt-4.7/webkit-framecapture.html

like image 110
Marçal Juan Avatar answered Sep 22 '22 05:09

Marçal Juan


QWebPage can be used in a widget-less environment.

To load a page, do something like this

QWebPage page;
QUrl url = ...;
page.mainFrame()->load(url);

To get access to the DOM tree, you can use QWebFrame::documentElement(). See the API for how to use this.

like image 20
mtvec Avatar answered Sep 19 '22 05:09

mtvec