PDA

View Full Version : Embed Qt Widgets in a browser



Nightfox
29th July 2012, 14:51
I really want to display my own widgets in a browser as a web application. I've found a great example on http://doc.qt.nokia.com/qq/qq26-webplugin.html.
When I run the .html file however, it doesn't show the QTableView in the browser. It reports an error saying "No plug-in available to display this content". Running the Qt app however works fine. How can I create web pages to display my own Qt widget that the user can browse to through html (ie. how to open the html in a standard browser and it will show the Qt Widget)? Does the plug-in need to be at a certain location in order to work?

amleto
29th July 2012, 16:04
it needs every single user to download something first for that to work

Nightfox
29th July 2012, 16:43
Well, for starters it doesn't even run on my machine. The Qt app sure, but not when I open the html file on chrome/firefox. Where should the class/widget be stored to make it run in the browser? If it can't then there's really no point of developing web applications, is there?

d_stranz
29th July 2012, 16:49
I think you're a bit confused about QtWebKit. It lets you display web pages within a Qt application, which is why you can embed Qt widgets into the pages. It isn't using Chrome, Firefox, or some other browser to display the widgets (or the html), it is using the QWebView widget running inside of QApplication.

Nightfox
29th July 2012, 18:29
That's why I prefer the plug-in approach (see my post above) and not to rely on the QtWebkit to be installed on the user machine. Are you saying that there no way to display QWidgets inside a web browser like chrome and firefox?

amleto
29th July 2012, 22:02
That's why I prefer the plug-in approach (see my post above) and not to rely on the QtWebkit to be installed on the user machine. Are you saying that there no way to display QWidgets inside a web browser like chrome and firefox?

Inherently those widgets need qt dlls. so without the user installing something, and you making widgets compatible with browsers (activex ?), then it's not going to happen.

d_stranz
1st August 2012, 04:33
not to rely on the QtWebkit to be installed on the user machine.

I think you're still confused. QtWebKit basically is a browser that can be embedded in a Qt application. As amleto says, you can't plug QtWebKit into some other browser, nor can you plug other Qt widgets into another browser except by wrapping them in some framework that the browser understands. Anything that uses Qt widgets requires the Qt DLLs that contain the widgets to be installed locally on the user's machine. You can't get around this - if the code isn't installed, nothing happens because there is no code to run when the browser needs to display something.

So even if you did have a way to create a plugin that could be loaded by Firefox, you would still have to deploy it along with all of the Qt DLLS needed. (Or, build a static library version of Qt and link that to your plugin, but deploying the plugin still means dragging along all the statically-linked Qt code when your plugin downloads to the user's machine - there is no free lunch).

I'm still not even sure that could be made to work - who is going to be running the Qt event loop? Firefox won't be, so it has to be running inside your plugin and that implies your plugin is an EXE.

samiswt
8th August 2012, 02:18
I don't think QWebKit is a browser and it is not actually.
Nightfox, all you have to do, briefly:
1.Create a new project, C++ library or widget, what ever;
2.Create your own plugin things and compile them as .dll or .so which depends on the OS you used.
3.In your .html adds <object> tag to load your plugin.

The example you mentioned is C++ Console project. The plugin in the example can not be used directly in any webpage.
Actually, I'm working on the webplugin developed using QT. My question now is about how to pass the parameter in <object> tag to my dll.
As long as I finish my work, I'll share with you.

ChrisW67
8th August 2012, 03:49
For the Microsoft browsers you can create your widget as an ActiveX control and embed it that way. The Qt libraries are shipped in the CAB file for the embeddable control. There's an example of exactly this in the ActiveQt docs. This is clearly Windows-only.

For the Netscape browser derivatives you can try to wrap your widget in the NPAPI (http://en.wikipedia.org/wiki/NPAPI) wrapper these browsers expect. This can be done using C and really has little to do with Qt). You'll need to build a version for Windows/Linux/Mac etc.

Seriously though, you are going to have to distribute just as much compiled code to do this in a browser as you would to do it as a standalone app.


None of this has much to do with the example you linked to. That example talks about features of the bridge between your Qt application and an embedded QtWebKit browser widget. This coupling allows more direct insertion of Qt widgets as plugins in the QtWebkit browser view. Nothing here supports external browsers.

d_stranz
8th August 2012, 04:57
None of this has much to do with the example you linked to. That example talks about features of the bridge between your Qt application and an embedded QtWebKit browser widget. This coupling allows more direct insertion of Qt widgets as plugins in the QtWebkit browser view. Nothing here supports external browsers.

Yes, that's exactly the point we're trying to make. QtWebKit is not a tool for embedding Qt widgets in some 3rd party browser, it is a way to create a browser-like GUI within a Qt application.

@samiswt:


1.Create a new project, C++ library or widget, what ever;
2.Create your own plugin things and compile them as .dll or .so which depends on the OS you used.
3.In your .html adds <object> tag to load your plugin.

Wrong. You cannot display or interact with Qt widgets embedded in an external browser (like Firefox, Chrome, or IE) without also deploying all of the Qt DLLS you need to support those widgets and putting those widgets within a framework (such as ActiveX) that the browser can understand.

Nightfox
17th August 2012, 22:31
Hey guys,
Sorry for not participating in this thread for a long time. I've been on vacation.

What inspired me to start this thread was the idea of displaying my own chart library on a web browser. See the library here:
http://qt-apps.org/content/show.php/OChartView?content=149760
I wanted to build a reporting (desktop) application and have the chart in it. Then port it to an internet application later on.

So, when reading the first chapter of Mark Summerfields book (Advanced Qt Programming) about Hybrid Desktop/Internet Applications, I got sparked on because of the tablewidget subclass in a browser in the example. I understood that new features of HTML5 and QWebKit would enable web browsers to render QWidgets without any plugins or installation. This is sadly not the case for the reasons listed by d_stranz. I actually contacted Mr. Summerfield directly about this and let me share with you his response;



[...]So, the only way to get it to work with HTML files is to create your own
browser (like the browser example in the book) and to add a file
association (or your operating system's equivalent) so that opening an
HTML file will open your browser. Unfortunately, your users won't want
this!

The only realistic prospect I can think of is to create browser-specific
plugins for all the browsers your users use. I don't think there's any
standard way to do this, so I think that this would be a lot of work --
as well as being frustrating as new browser versions might change their
plugin support.


This is bad news for people like me who has a set of QWidget/QAbstratItemView subclasses that we want to share with the world through the web. The (easiest) solution to this is to build web applications that run server side, sort of like Java Swing on apache server. Wt (http://www.webtoolkit.eu/wt) does exactly this but QWidgets can not be used/rendered - at least I haven't seen a working example of this.

And now I'm back to square one because I don't want to rewrite my chart library in Java or use flash. Any suggestions?

d_stranz
17th August 2012, 22:39
And now I'm back to square one because I don't want to rewrite my chart library in Java or use flash. Any suggestions?

Probably not really a viable solution but SVG could be an option, and Qt supports SVG rendering. This is a pretty interesting example (http://croczilla.com/bits_and_pieces/svg/samples/svgtetris) of what you can do with SVG. If you're considering a web server approach, you could render the charts to SVG and serve up the result.

ChrisW67
17th August 2012, 22:46
There are plenty of options for charting in web browsers using jQuery and other Javascript libraries. You will not avoid reworking your code but perhaps you could adapt the code currently in your paintEvent() to generate Javascript equivalent output. Generally the Javascript libraries operate at a higher level though.

Edit: Or render to a pixmap that you can then send that to the browser for static display.

maximebd
17th August 2012, 22:52
Ok, so this is something I have done for the corporation I work for, unfortunately, it also means that I cannot share many details. What I did was to make a Qt application run from within the browser but as a separate process called from a browser plugin. I used firebreath (http://www.firebreath.org/display/documentation/FireBreath+Home) to make the cross platform/browser plugin. When I got that part working, getting Qt to show in the browser was just a matter of sending the parent window ID as a command line parameter to the application and setting it as the parent.



#include <QApplication>
#include <QWidget>

#include <windows.h>

#pragma comment(lib, "user32.lib")

int main(int argc, char *argv[])
{
QApplication application(argc, argv);

QWidget widget;

widget.setAttribute(Qt::WA_NativeWindow);
SetParent(widget.winId(), (WId)QString::toULong(application.arguments().at(1 )));

widget.show();

return application.exec();
}