PDA

View Full Version : embedding X11



afflictedd2
9th February 2009, 18:52
Hi everyone,

I'm creating an interface that calls on a program with a given set of parameters, and then the program is run with QProcess, but it is displayed in a sepparate X11 window

I would like to embed this in the Mainwindow, but I'm not sure how to do this. Any ideas?

caduel
9th February 2009, 19:02
use QX11EmbedContainer; you need to wait for your program to get started and find out its X11 window id
(some programs let you pass a window id they should embed into, too)

afflictedd2
11th February 2009, 21:44
Hi caduel,

I am testing it out with xlogo. I tried it on Mac, it didn't compile. It said that QX11EmbedContainer class didn't exist. Is this class available for Macs?

I tried it on unix, and it worked compiled and ran, however I don't see the logo embedded in the application. I think it's because I don't know the windows id, how do I find that id?

caduel
12th February 2009, 08:04
macs: sorry. don't have one. i think that it should work on macs if and only if the mac is running X11.

window id: to find the window id of an existing window: use X11 calls to traverse (query) the window tree and find the window e.g. thru comparing window titles. (see X11 calls like XQueryTree, XWindowName, ...).

afflictedd2
12th February 2009, 16:19
So if I understand correctly, the x11 program I want to run embeded, must have a way to specify the winId. Otherwise the QX11EmbedContainer will not work. This is the code that runs but doesn't work, I think it doesn't have a way to specify the winId as an argument.



#include <QX11EmbedContainer>
#include <QtGui>
#include <QProcess>

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

if (app.arguments().count() != 2) {
qFatal("Error - expected executable path as argument");
return 1;
}

QX11EmbedContainer container;
container.show();

QProcess process(&container);
QString executable(app.arguments()[1]);
QStringList arguments;
arguments << QString::number(container.winId());
process.start(executable, arguments);

int status = app.exec();
process.close();
return status;
}

caduel
13th February 2009, 08:38
this is one way: if an app allows you to pass a window id for rendering into, then you can do that.

if you have an app that does not allow you to pass a window id that way, then you call QX11EmbedContainer::embedClient() with the window id of the client app.
(To do that: start the app, wait for the window to exist, get its window id, then call embedClient with that id.)