QtWebkit as a desktop application GUI

This won't be easy: Web browsers are fortresses because of security concerns. So it's pretty hard to get from JS in a web page to something outside of the browser.

Also, QtWebKit isn't a very open API. The biggest obstacle in your case is that it doesn't offer you access to the DOM, so you can only replace the whole HTML.

Therefore, you'll need to patch and write a lot of code to implement the missing APIs and functions.

Since Qt 4.6 has been released, there is QWebElement (see the docs for examples), so you can at least access the DOM and modify it. That will make a lot of things more simple. I suggest to decide who controls the browser: Will your app be JavaScript which calls outside or is the app really in C++ and you use the browser as a smart UI renderer?

A much more simple way might be to make your idea work would be to start an internal web server when your app starts and then open a QtWebKit view pointing to the URL of the local server. Then, you could use all the standard web development tools. Eclipse uses this technique for its internal help system.


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.


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/