Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt+Cef integration on Linux
QtWS25 Last Chance

Qt+Cef integration on Linux

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 5 Posters 10.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antofik
    wrote on 28 Dec 2016, 15:54 last edited by
    #1

    I'm trying to create Qt application with Cef browser working on Linux (Debian Wheezy)
    Versions: Qt 5.5, Cef 1547
    Basically, I have QWidget with following browser initialization code:

    CefwindowInfo info;
    QWindow* win = new QWindow();
    this->layout()->addWidget(QWidget::createWindowContainer(win));
    info.SetAsChild((CefWindowHandle)win->winId());
    CefBrowserHost::CreateBrowser(info, ...);
    

    This code causes Segmentation fault exception with following callstack

    0> g_type_check_instance_cast
    1> CefBrowserHostImpl::PlatformCreateWindow()
    2> ??
    

    If I comment out the line with info.SetAsChild(..) , everything works as expected save that Cef is launched in separate window, while I need it to be integrated in my Qt application.

    Any ideas what am I doing wrong?

    K 1 Reply Last reply 28 Dec 2016, 16:02
    0
    • A antofik
      28 Dec 2016, 15:54

      I'm trying to create Qt application with Cef browser working on Linux (Debian Wheezy)
      Versions: Qt 5.5, Cef 1547
      Basically, I have QWidget with following browser initialization code:

      CefwindowInfo info;
      QWindow* win = new QWindow();
      this->layout()->addWidget(QWidget::createWindowContainer(win));
      info.SetAsChild((CefWindowHandle)win->winId());
      CefBrowserHost::CreateBrowser(info, ...);
      

      This code causes Segmentation fault exception with following callstack

      0> g_type_check_instance_cast
      1> CefBrowserHostImpl::PlatformCreateWindow()
      2> ??
      

      If I comment out the line with info.SetAsChild(..) , everything works as expected save that Cef is launched in separate window, while I need it to be integrated in my Qt application.

      Any ideas what am I doing wrong?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 28 Dec 2016, 16:02 last edited by
      #2

      Hi,
      You're probably passing a nullptr to the SetAsChild method. You should check that as a first step. Secondly, if you're dealing with widgets then the widget may not have a window handle at all (if it's a child to another widget) as Qt optimizes the number of handles used and only root-level widgets get a X window, although a handle should be created when the call is made. And lastly, depending on where you call this code (the snippet) Qt may have not yet created the handle (if at all).

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        antofik
        wrote on 28 Dec 2016, 16:27 last edited by
        #3

        Thank you, kshegunov, for you replies.
        SetAsChild receives valid handle. QWindow in Qt was designed specifically to be the point of integration between different windows. I'm running the code in debug mode, so no optimizations are applied. The above code itself is executed without exceptions. The problem happens somewhere inside CefDoMessageLoopWork() later.

        K 1 Reply Last reply 29 Dec 2016, 22:03
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 28 Dec 2016, 17:00 last edited by
          #4

          Hi
          Just to be sure.
          Its not CefwindowInfo info;
          running out of scope?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            antofik
            wrote on 28 Dec 2016, 17:06 last edited by
            #5

            No, mrjj, it is not "out-of-scope" issue. The problem is in some kind of validation of QWindow->winId() handle by gnome g_type_check_instance_cast. As if QWindow->winId() returns not the type of object expected by Cef. Should it be GtkWindow*?

            M 1 Reply Last reply 28 Dec 2016, 17:10
            0
            • A antofik
              28 Dec 2016, 17:06

              No, mrjj, it is not "out-of-scope" issue. The problem is in some kind of validation of QWindow->winId() handle by gnome g_type_check_instance_cast. As if QWindow->winId() returns not the type of object expected by Cef. Should it be GtkWindow*?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 28 Dec 2016, 17:10 last edited by mrjj
              #6

              @antofik
              That could be as
              http://magpcss.org/ceforum/apidocs3/projects/(default)/CefWindowInfo.html#SetAsChild(cef_window_handle_t,RECT)
              Seems to want a cef_window_handle_t and not the Wld (even u cast it)
              Its unclear if it wants one of its own windows or can accept platform "ID"

              A 1 Reply Last reply 28 Dec 2016, 20:20
              0
              • M mrjj
                28 Dec 2016, 17:10

                @antofik
                That could be as
                http://magpcss.org/ceforum/apidocs3/projects/(default)/CefWindowInfo.html#SetAsChild(cef_window_handle_t,RECT)
                Seems to want a cef_window_handle_t and not the Wld (even u cast it)
                Its unclear if it wants one of its own windows or can accept platform "ID"

                A Offline
                A Offline
                antofik
                wrote on 28 Dec 2016, 20:20 last edited by
                #7

                @mrjj, you've hit the point. The problem is to pass to SetAsChild() something it will be happy with... But what it is?

                M 1 Reply Last reply 28 Dec 2016, 21:05
                0
                • A antofik
                  28 Dec 2016, 20:20

                  @mrjj, you've hit the point. The problem is to pass to SetAsChild() something it will be happy with... But what it is?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 28 Dec 2016, 21:05 last edited by
                  #8

                  @antofik
                  Well is it make for linux?
                  http://magpcss.org/ceforum/apidocs3/projects/(default)/_cef_window_info_t.html
                  Really seems windows-ish for me using HWND and DWORD
                  Also on the download page
                  https://code.google.com/archive/p/chromiumembedded/downloads
                  I see no linux?
                  Of Course it works on linux too but if u check out the
                  cef_window_handle_t ( right click and go to definition)
                  is that also using DWORD and HWND or what is the internals in your version?

                  A 1 Reply Last reply 29 Dec 2016, 09:42
                  0
                  • M mrjj
                    28 Dec 2016, 21:05

                    @antofik
                    Well is it make for linux?
                    http://magpcss.org/ceforum/apidocs3/projects/(default)/_cef_window_info_t.html
                    Really seems windows-ish for me using HWND and DWORD
                    Also on the download page
                    https://code.google.com/archive/p/chromiumembedded/downloads
                    I see no linux?
                    Of Course it works on linux too but if u check out the
                    cef_window_handle_t ( right click and go to definition)
                    is that also using DWORD and HWND or what is the internals in your version?

                    A Offline
                    A Offline
                    antofik
                    wrote on 29 Dec 2016, 09:42 last edited by
                    #9

                    @mrjj
                    Yes, it fully supports Linux. Moreover, it is even embeddable into Qt. But unfortunately there are no open examples.
                    Here https://bitbucket.org/chromiumembedded/cef/src/master/tests/cefclient/cefclient_gtk.cc?at=master&fileviewer=file-view-default you could find an example how to do it with Gtk+. Now, I need to somehow connect Qt and Cef with or without Gtk+ intermediate layer.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 29 Dec 2016, 10:00 last edited by
                      #10

                      Ok, but since you are using the
                      win->winId()
                      That will give you the native handle for a window for the display/deskop manager you are using. ( AFAIK)
                      So if NOT gtk as your desktop, will it then work with Cef ?
                      Are you on KDE or what linux ?

                      1 Reply Last reply
                      0
                      • A antofik
                        28 Dec 2016, 16:27

                        Thank you, kshegunov, for you replies.
                        SetAsChild receives valid handle. QWindow in Qt was designed specifically to be the point of integration between different windows. I'm running the code in debug mode, so no optimizations are applied. The above code itself is executed without exceptions. The problem happens somewhere inside CefDoMessageLoopWork() later.

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 29 Dec 2016, 22:03 last edited by kshegunov
                        #11

                        @antofik said in Qt+Cef integration on Linux:

                        The problem happens somewhere inside CefDoMessageLoopWork() later.

                        Pull a trace out of that. And also bear in mind Qt very much dislikes sharing the (system) event loop with other things, so I'm still not convinced that integration is possible between these two libraries.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          antofik
                          wrote on 30 Dec 2016, 13:16 last edited by
                          #12

                          Actually, I've managed to make it work.
                          Just in case, if someone will need it in future:

                            GtkWidget* gtkWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                            GtkWidget* parentView = gtk_vbox_new(FALSE, 0);
                            GtkContainer* container = (GTK_CONTAINER(gtkWin));
                            gtk_container_add(container, parentView);
                            gtk_window_set_position(GTK_WINDOW(gtkWin), GTK_WIN_POS_CENTER);
                            gtk_widget_show_all(GTK_WIDGET(gtkWin));
                          
                            GdkWindow* w = gtk_widget_get_window(parentView);
                            XID t = gdk_x11_drawable_get_xid(w);
                          
                            WId wid = (WId) t;
                            QWindow* win = QWindow::fromWinId(wid);
                            setLayout(new QGridLayout());
                            QWidget* widget = QWidget::createWindowContainer(win);
                            this->layout()->addWidget(widget);
                          
                            info.SetAsChild(parentView);
                          

                          Basically, I've created my own GTK window, passed the reference on this window to CEF, and placed it into Qt widget using QWindow::fromWinId().

                          T 1 Reply Last reply 25 Sept 2020, 06:18
                          1
                          • M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 30 Dec 2016, 13:30 last edited by
                            #13

                            So would it be fair to conclude that it really
                            wants a gtk windows handle and not what ever comes out of
                            winId() ?

                            A 1 Reply Last reply 30 Dec 2016, 14:06
                            0
                            • M mrjj
                              30 Dec 2016, 13:30

                              So would it be fair to conclude that it really
                              wants a gtk windows handle and not what ever comes out of
                              winId() ?

                              A Offline
                              A Offline
                              antofik
                              wrote on 30 Dec 2016, 14:06 last edited by
                              #14

                              Yes @mrjj, Cef is built on Gtk2, so it requires gtk handle, not the winId().

                              Anyhow, it is possible to integrate Cef with Qt on linux, and that is what matters :-)

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                gepgep
                                wrote on 10 Mar 2017, 16:50 last edited by
                                #15

                                is there somewhere a more complete example of mixing qt/gtk/cef?

                                M 1 Reply Last reply 10 Mar 2017, 16:54
                                0
                                • G gepgep
                                  10 Mar 2017, 16:50

                                  is there somewhere a more complete example of mixing qt/gtk/cef?

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 10 Mar 2017, 16:54 last edited by
                                  #16

                                  @gepgep
                                  Not that i have stumbled upon.
                                  Have you asked on the forum ?
                                  http://magpcss.org/ceforum/

                                  You cannot use http://doc.qt.io/qt-5/qtwebengine-index.html
                                  or webkit ?

                                  G 1 Reply Last reply 10 Mar 2017, 17:01
                                  0
                                  • M mrjj
                                    10 Mar 2017, 16:54

                                    @gepgep
                                    Not that i have stumbled upon.
                                    Have you asked on the forum ?
                                    http://magpcss.org/ceforum/

                                    You cannot use http://doc.qt.io/qt-5/qtwebengine-index.html
                                    or webkit ?

                                    G Offline
                                    G Offline
                                    gepgep
                                    wrote on 10 Mar 2017, 17:01 last edited by
                                    #17

                                    @mrjj i am wondering if it can be done with cef due to (my) project restrictions ..
                                    I have found several git repos with qt+cef, but only for windows. Also i managed to combine gtk with cef successfully, but i cant find anything about qt+cef@linux (maybe because qt+gtk is not a happy combination?). The code snippet from @antofik does not build (gtkwidget with qwidget is it even possible) or i am missing something?

                                    M 1 Reply Last reply 10 Mar 2017, 17:10
                                    0
                                    • G gepgep
                                      10 Mar 2017, 17:01

                                      @mrjj i am wondering if it can be done with cef due to (my) project restrictions ..
                                      I have found several git repos with qt+cef, but only for windows. Also i managed to combine gtk with cef successfully, but i cant find anything about qt+cef@linux (maybe because qt+gtk is not a happy combination?). The code snippet from @antofik does not build (gtkwidget with qwidget is it even possible) or i am missing something?

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 10 Mar 2017, 17:10 last edited by
                                      #18

                                      @gepgep
                                      Well mixing Gtk and Qt is pretty rare use case as far as I know. Both being Widgets libraries.
                                      And there is always the issue of the event loop.
                                      So as far as integration it will not be funny.

                                      @antofik sample wraps a gtk window using native Gtk calls +Qt and is apparently supported by
                                      createWindowContainer so in this case it works.

                                      I have not seen much info about this. sorry.

                                      G 1 Reply Last reply 13 Mar 2017, 08:17
                                      1
                                      • M mrjj
                                        10 Mar 2017, 17:10

                                        @gepgep
                                        Well mixing Gtk and Qt is pretty rare use case as far as I know. Both being Widgets libraries.
                                        And there is always the issue of the event loop.
                                        So as far as integration it will not be funny.

                                        @antofik sample wraps a gtk window using native Gtk calls +Qt and is apparently supported by
                                        createWindowContainer so in this case it works.

                                        I have not seen much info about this. sorry.

                                        G Offline
                                        G Offline
                                        gepgep
                                        wrote on 13 Mar 2017, 08:17 last edited by
                                        #19

                                        @mrjj thanks for your time+replies

                                        M 1 Reply Last reply 13 Mar 2017, 08:33
                                        0
                                        • G gepgep
                                          13 Mar 2017, 08:17

                                          @mrjj thanks for your time+replies

                                          M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 13 Mar 2017, 08:33 last edited by
                                          #20

                                          @gepgep
                                          Hi
                                          Just as a note.
                                          Webkit been revived
                                          https://forum.qt.io/topic/76739/webkit-status-2017

                                          So you might be able to use that?

                                          1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved