views:

476

answers:

4

Hi

I was wondering if anyone knows about good tutorials or articles describing methods of creating an HTML GUI for an application using QTWebKit for a windows desktop application.

I am mainly concerned about communicating messages, events and information between lets say a DLL(written in C++ for example) and the GUI (QtWebKit).

need good reliable references...

+2  A: 
Aaron Digulla
doeesn't QWebElement and QWebElementSelection give access to manipulating DOM elements??
Red Serpent
It does........
Georg Fritzsche
I wasn't aware that Qt 4.6 has already been release. You're right, see this link: http://doc.trolltech.com/4.6/qt4-6-intro.html#dom-access-api
Aaron Digulla
I've improved my answer.
Aaron Digulla
Its the latter case "app really in C++ and you use the browser as a smart UI renderer"
Red Serpent
Aaron, mapping script calls to C++ and event handling is in my opinion complicated by routing it through an additional layer (i.e. the webserver). Also, implementing custom drawn elements (video, ...) gets quite hackish.
Georg Fritzsche
+2  A: 

This might help:

http://labs.trolltech.com/blogs/2009/04/07/qwebelement-sees-the-light-do-i-hear-a-booyakasha/

http://labs.trolltech.com/blogs/2009/04/17/jquery-and-qwebelement/

guruz
I was just looking into the first link just now, and maybe thats the solution.... I think I'll have to study the classes well first before moving on just to see if these are the ultimate solution.Still not sure about the communication bit from the DLL to the page...
Red Serpent
+2  A: 

For the basic usage, the examples from trolltech should get you started.

The plus-side of the Qt approach is that exposing objects to the script is relatively easy, see e.g. here. JavaScript in the different embedded webkits can then easily communicate with C++ (and of course with script in other windows if you provide support on the C++ side for that). The down-side is that the API doesn't seem to be quite stable yet and seems to be missing support for adding event listeners from JavaScript to C++ objects (or at least i didn't see how it was supposed to be done).

Placing custom drawn elements into the page is again quite simplified, you embed plugins into the page (e.g. via the <object> tag) and return custom QWidgets from QWebPluginFactory::create().

On important thing to always keep in mind: calls to the embedded webkit (e.g. for evaluating JavaScript) should always occur on the main thread.

Georg Fritzsche
Thank you for an insightful comment. Can you provide any more information on why "calls to the embedded webkit (e.g. for evaluating JavaScript) should always occur on the main thread"?
EightyEight
In any current browser i know of the script engine resides in the main thread and is not thread-safe. The plugin-developer has to make sure that the calls into the browser are issued from the right thread unless some API functions already take care of that - if you don't you get undefined behaviour and most likely crashes.
Georg Fritzsche
+1  A: 

i'm copy/pasting bits from different sections but this is how i insert an object that is available to javascript, then i use javascript to talk to the main app. seems to work well...

void MyApi::setWebView( QWebView *view ) {

QWebPage *page = view->page();
m_frame = page->mainFrame();

attachObject();
connect( m_frame, SIGNAL(javaScriptWindowObjectCleared()), 
    this, SLOT(attachObject()) );

}

void MyApi::attachObject() {

m_frame->addToJavaScriptWindowObject( QString("MyApi"), this );

}

this makes a "MyApi" object exist in javascript and i can call any slots made available from the MyApi class.

miguel deanda