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. Problem with successive attempts to embed external app in QT Widget
Forum Update on Monday, May 27th 2025

Problem with successive attempts to embed external app in QT Widget

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 532 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.
  • W Offline
    W Offline
    walle19
    wrote on 13 Jan 2021, 17:36 last edited by
    #1

    Hi All,

    QT Version: 4.7.1
    Platform: Linux Kubuntu 14
    Compiler: c++11

    After a long period of research on the web and forums, I successfully managed to use QX11EmbedContainer in order to embed a external application into a QT Widget.

    The QT application holds a push button that is pressed by the user.
    This is the general implemenation. How i get the window id is not of importance:

    Demo::Demo() {
    QX11EmbedContainer *container = new QX11EmbedContainer(parent);
    layout->addWidget(container);
    }

    WId Demo::getWinID() {
    //Implementation
    }

    void Demo::runExternalApp() {
    //Implementation
    }

    void Demo::on_runAppButton_clicked() {
    runExternalApp()
    container->embedClient(getWinID());
    }
    To copy to clipboard, switch view to plain text mode

    After pressing the button, and the call to embedClient() the external application is successfully embedded exactly where I want it to, and its also functioning properly.
    My problem starts when I try to close the external application regularly (from within my QT application) and then re-press the push button that embeds the external application (on_runAppButton_clicked()).
    The external application is terminated properly when regularly exiting from it.
    After pressing the push button again: the application is re-executed properly and embedded, but this time, it is embedded with a offset from the bottom of the layout that holds the container widget (QX11EmbedContainer widget).

    Bare in mind the QT application keeps running throughout this process without terminating - The layout, container widget and parent widget aren't destroyed or anything like that.

    Your help will be very helpful,
    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Jan 2021, 17:59 last edited by
      #2

      Hi,

      Did you ensure that the layout is empty after removing that embedded application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply 13 Jan 2021, 18:34
      0
      • S SGaist
        13 Jan 2021, 17:59

        Hi,

        Did you ensure that the layout is empty after removing that embedded application ?

        W Offline
        W Offline
        walle19
        wrote on 13 Jan 2021, 18:34 last edited by walle19
        #3

        @SGaist thanks for the reply,
        Is there a programmatic way to check if the layout is empty?

        I used: layout->count() but oddly, the number of items before and after calling
        layout->addWidget() is 0.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Jan 2021, 19:33 last edited by
          #4

          Do you have any stretch added ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          W 1 Reply Last reply 13 Jan 2021, 19:42
          0
          • S SGaist
            13 Jan 2021, 19:33

            Do you have any stretch added ?

            W Offline
            W Offline
            walle19
            wrote on 13 Jan 2021, 19:42 last edited by
            #5

            @SGaist no, the QX11EmbedContainer object's parent is a QWidget and its size policy is [Preffered, Preffered].
            Regarding the QX11EmbedContainer itself I didn't explicitly define any stretching.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              walle19
              wrote on 13 Jan 2021, 19:56 last edited by
              #6

              Interesting fact:
              I now noticed that after the second execution of the external application and embedding, and seeing that the embedded app is offset from bottom of layout as mentioned,
              If I double click the GUI of the qt app in order to minimize the whole window ("restore down") and then maximizing it, the external app suddenly fits in place.
              Is there some sort of refresh method i need to invoke ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 13 Jan 2021, 20:04 last edited by
                #7

                Does it also happen on resize ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                W 1 Reply Last reply 13 Jan 2021, 20:09
                0
                • S SGaist
                  13 Jan 2021, 20:04

                  Does it also happen on resize ?

                  W Offline
                  W Offline
                  walle19
                  wrote on 13 Jan 2021, 20:09 last edited by
                  #8

                  @SGaist if i understood the question correctly, then when resizing the qt gui main window the embedded external app doesn't get offset. It behaves properly.
                  The offset is introduced only on the second attempt to embed it.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 13 Jan 2021, 20:12 last edited by
                    #9

                    Sorry, I meant: after the second embedding, if you resize the container widget, does it also fix the positioning issue ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    W 1 Reply Last reply 13 Jan 2021, 20:23
                    0
                    • S SGaist
                      13 Jan 2021, 20:12

                      Sorry, I meant: after the second embedding, if you resize the container widget, does it also fix the positioning issue ?

                      W Offline
                      W Offline
                      walle19
                      wrote on 13 Jan 2021, 20:23 last edited by
                      #10

                      @SGaist It seems it did. This is very interesting.
                      I called the containers resize() method right after the embedClient().
                      The remote application didn't actually change size to what i specified in resize() and stills fits as intended to it's dedicated layout.
                      After the second execution of external app again the resize() and embedClient() are called but now the offset has disappeared.
                      Any conclusion ?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 13 Jan 2021, 20:58 last edited by
                        #11

                        @walle19 said in Problem with successive attempts to embed external app in QT Widget:

                        Any conclusion ?

                        Embedding is tricky ! But also, you are using a version of Qt that is way more than outdated. If locked to Qt 4, you should check with the latest release of that series which is 4.8.7.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        1/11

                        13 Jan 2021, 17:36

                        • Login

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