Solved Problem with successive attempts to embed external app in QT Widget
-
Hi All,
QT Version: 4.7.1
Platform: Linux Kubuntu 14
Compiler: c++11After 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 modeAfter 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 -
Hi,
Did you ensure that the layout is empty after removing that embedded application ?
-
@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. -
Do you have any stretch added ?
-
@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. -
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 ? -
Does it also happen on resize ?
-
@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. -
Sorry, I meant: after the second embedding, if you resize the container widget, does it also fix the positioning issue ?
-
@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 ? -
@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.