|
|
> > QTextBrowser is not a web browser, so for arbitrary web pages it simply
> > won't work.
>
> Ah, but it's possible to get it to download pages using HTTP and display
> them. It just doesn't do it by default.
Sure. Forget the fact that most of the content out there simply won't display
in any meaningful way :)
If it just about getting the stuff that QTextBrowser can handle from the web,
then simply do
QUrlOperator * op;
User * user; // a class that handles all the data
user = new User();
qInitNetworkProtocols();
op = new QUrlOperator( "http://www.trolltech.com" );
connect(op, SIGNAL(data(const QByteArray &, QNetworkOperation *)), user,
SLOT(data(const QByteArray &)));
connect(op, SIGNAL(finished(QNetworkOperation *)), user, SLOT(done()));
op.get( "index.html" );
Accumulate data in User::data(...) [slot] and then feed it to the browser in
User::done() [slot]
If you want to make the browser get images, you have to implement your own
derivative of QMimeSourceFactory, especially the data(const QString &)
method. You you'd give that factory to the browser so that it knows how to
obtain data for any images referenced in the quasi-html page source. Then you
reimplement linkClicked to handle loading of new pages, which can be done
fully asynchronously.
Since QMimeSourceFactory can only provide a blocking interface, you'd probably
need to treat all initial requests for images from the mime source as "fetch"
requests, and then set the data source of the browser again (i.e. refresh)
when all (or at least some) of the images have finished loading.
It'd be an interesting exercise to see how small the whole code can be to do
it in a functional way.
Cheers, Kuba
--
List archive and information: http://lists.trolltech.com/qt-interest/
|
|