Results 1 to 9 of 9

Thread: Getting a parent window from a QT/Linux library

  1. #1
    Join Date
    May 2007
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Getting a parent window from a QT/Linux library

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting a parent window from a QT/Linux library

    Yup, you have the QX11Info class ;-)

    And this method might be just what you need !

    Qt::HANDLE QX11Info::appRootWindow()

  3. #3
    Join Date
    May 2007
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Getting a parent window from a QT/Linux library

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Getting a parent window from a QT/Linux library

    What do you mean by a "parent application"?

  5. #5
    Join Date
    May 2007
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Getting a parent window from a QT/Linux library

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting a parent window from a QT/Linux library

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2007
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Getting a parent window from a QT/Linux library

    You're right but I'd like to find another way to solve this problem, without asking anything to the parent application.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Getting a parent window from a QT/Linux library

    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.

  9. #9
    Join Date
    May 2007
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Getting a parent window from a QT/Linux library

    I've found some solutions with bash and X11 but it's dirty. Ithink you're probably right. Thank tou.

Similar Threads

  1. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.