Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtWebkit as a desktop application GUI [closed]

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...

like image 205
Zaid Amir Avatar asked Jan 11 '10 09:01

Zaid Amir


4 Answers

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.

like image 61
Aaron Digulla Avatar answered Sep 25 '22 21:09

Aaron Digulla


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.

like image 39
miguel deanda Avatar answered Sep 21 '22 21:09

miguel deanda


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/

like image 31
guruz Avatar answered Sep 23 '22 21:09

guruz


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.

like image 20
Georg Fritzsche Avatar answered Sep 21 '22 21:09

Georg Fritzsche