Results 1 to 15 of 15

Thread: Embed Qt Widgets in a browser

  1. #1
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Embed Qt Widgets in a browser

    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?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    it needs every single user to download something first for that to work
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Embed Qt Widgets in a browser

    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?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Embed Qt Widgets in a browser

    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?

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    Quote Originally Posted by Nightfox View Post
    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. The following user says thank you to d_stranz for this useful post:

    Cupidvogel (24th February 2016)

  9. #8
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Cool Re: Embed Qt Widgets in a browser

    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.

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Embed Qt Widgets in a browser

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

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. The following 2 users say thank you to d_stranz for this useful post:

    Cupidvogel (24th February 2016), samiswt (8th August 2012)

  13. #11
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Embed Qt Widgets in a browser

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

  14. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Embed Qt Widgets in a browser

    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 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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  15. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Embed Qt Widgets in a browser

    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.
    Last edited by ChrisW67; 17th August 2012 at 21:54. Reason: updated contents

  16. #14
    Join Date
    Aug 2012
    Location
    Montreal
    Posts
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Embed Qt Widgets in a browser

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

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3.  
    4. #include <windows.h>
    5.  
    6. #pragma comment(lib, "user32.lib")
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication application(argc, argv);
    11.  
    12. QWidget widget;
    13.  
    14. widget.setAttribute(Qt::WA_NativeWindow);
    15. SetParent(widget.winId(), (WId)QString::toULong(application.arguments().at(1)));
    16.  
    17. widget.show();
    18.  
    19. return application.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

  17. The following user says thank you to maximebd for this useful post:

    arminIT (21st January 2013)

  18. #15
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Exclamation Re: Embed Qt Widgets in a browser

    Just because chrome or firefox is more popular than QT, that doesn't mean they are better or faster. With all the added crap on most all browsers anyway unless your actually browsing the net you're better off using anything else. My new fav browser went from opera to QT browser. Its under 10,000 kb and blazing fast. I used to be a chrome fan. I started using it cause it was supposed to be faster and have less bloatware extension BS. Then switched to Opera. Faster with better options and has the same menus as chrome now. Now days for speed, QT Browser or Green Browser are way smaller and faster. For synchronizing and using network drives and wireless W.A.N.S Sleepnir has the most functionality.

Similar Threads

  1. Embed VNC Viewer
    By NoRulez in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2021, 16:03
  2. Embed Qt Designer
    By emmynet in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2011, 14:52
  3. Replies: 0
    Last Post: 17th March 2011, 03:17
  4. Not able to run fancy browser and demo browser example applications
    By GoGetIt in forum Installation and Deployment
    Replies: 1
    Last Post: 16th August 2010, 06:23
  5. Embed platform-specific browser in QT app
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2007, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.