PDA

View Full Version : Getting a parent window from a QT/Linux library



nicolas44
29th May 2007, 17:28
Hi,

I'am developping a QT library that needs the parent window handle from the parent application.

Under windows XP I can use the class QWinWidget to use a MFC32 Window as a QWidget.

My question is: how can I do that with Linux? Is there a QX11Widget class?

Thank you.
Nicolas.

guilugi
29th May 2007, 17:44
Yup, you have the QX11Info class ;-)

And this method might be just what you need !

Qt::HANDLE QX11Info::appRootWindow()

nicolas44
30th May 2007, 09:23
Thank you for your answer!

I've tried the QX11Info::appRootWindow. I might not have understood how it works because I get a segmentation fault when I create a QWidget with the returned handle. Maybe the handle is the desktops one? Or maybe I just can't create a widget with that handle?

wysota
30th May 2007, 09:31
What do you mean by a "parent application"?

nicolas44
30th May 2007, 11:55
I have a static library loaded by an application (parent application). Each widget from my library needs a parent window. I don't want to use the desktop as a parent window, so I need to find the window of the parent application.

I use these fonctions to do that:

handle=QApplication::appRootWindow(0) to get the handle of parent application window.

parent=QWidget::find(handle) to create a Widget corresponding to the previous handle.

But I get a segmentation fault when I try to create a widget using parent.

I don't know if appRootWindow gives the desktops handle or my parent applications handle.

high_flyer
30th May 2007, 14:05
But if you are writing this lib your self, why don't you just make a method that accepts (and demands) the parent from the application?
So in your lib, you initialize a member variable, which is a QWidget pointer to NULL, and later check if it is not NULL - this means the application supplied a parent, if it is, through an exception, abort, or let your lib respond in any apropriate manner.
Clean, simple, and cross platform.

nicolas44
30th May 2007, 14:44
You're right but I'd like to find another way to solve this problem, without asking anything to the parent application.

wysota
31st May 2007, 02:09
What if something links to your library and wants to control what it does with its functionality? You shouldn't try to be smarter than the developer who will use your code. Let him/her decide what to pass as the parent.

nicolas44
31st May 2007, 09:17
I've found some solutions with bash and X11 but it's dirty. Ithink you're probably right. Thank tou.