Results 1 to 4 of 4

Thread: Inactive window Updation

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Inactive window Updation

    Hi,

    I have a requirement wherein, i need the handler for the main window of the application.
    For this i have used the code snippet,
    Qt Code:
    1. dial=(Ui_Dialog *)qApp->activeWindow();
    To copy to clipboard, switch view to plain text mode 
    (Ui_Dialog being the main window of application)

    This has one problem the data is not updated if the window is Inactive.
    Can anyone suggest what is to be done for this ?
    Last edited by jpn; 1st April 2008 at 07:06. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Inactive window Updation

    Introduce a direct pointer to the window, make it a singleton class, or find the window from the list of QApplication::topLevelWidgets()...
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inactive window Updation

    I tried using the topLevelWidgets function,
    Qt Code:
    1. foreach (QWidget *widget, QApplication::topLevelWidgets()) {
    2.  
    3.  
    4. if( widget->isWindow ())
    5. {
    6. dial = (Ui_Dialog *)widget;
    7. printf("hiding the window\n");
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    But i am getting segmentation fault.
    This might be because the application has more than one TopLevelWidget.
    In such a case how to i find a exact match for (Ui_Dialog *) ?
    Last edited by jpn; 1st April 2008 at 08:08. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Inactive window Updation

    First of all, QApplication::topLevelWidgets() returns a list of the top-level widgets (windows) in the application so there is no need to check if they are windows because they are. Secondly, don't use C-style cast, which makes no sanity checks at all, thus you'll get a crash when using something as Ui_Dialog which is not a Ui_Dialog. You should use dynamic_cast instead. But make sure to notice how dynamic_cast works (you should check the return value)!
    J-P Nurmi

Similar Threads

  1. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  2. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 08:16
  3. Replies: 1
    Last Post: 11th September 2007, 13:34
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  5. ToolWidgets disappear when window inactive
    By Moppel in forum Qt Programming
    Replies: 7
    Last Post: 5th January 2007, 21:50

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.