Results 1 to 3 of 3

Thread: Double window issue

  1. #1
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Double window issue

    I have a small app that launches a new window from a pushbutton click. is there anyway to detect the 2nd window and not open a new one until the old one is closed?

    psedo code.

    void MainWindow:n_Button_clicked()
    {
    MainForm* NewWindow;
    NewWindow = new MainForm();
    NewWindow->show();

    }

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Double window issue

    The easiest way I can think of to do this is to pass a pointer to the parent window to NewWindow, and use the pointer to call a function in MainWindow in the destructor of NewWindow.

    Something like:

    Qt Code:
    1. NewWindow::NewWindow(QWidget* parent)
    2. : QWidget(parent)
    3. {
    4. // Whatever
    5. }
    6. ~NewWindow::NewWindow()
    7. {
    8. (MainWindow*)parentWidget()->WindowClosed();
    9. }
    To copy to clipboard, switch view to plain text mode 

    You could then implement WindowClosed() something like this:

    Qt Code:
    1. void MainWindow::WindowClosed()
    2. {
    3. childWindowClosed = true;
    4. }
    To copy to clipboard, switch view to plain text mode 

    If there's a better way to do this, someone else might chime in.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Double window issue

    There are several techniques.
    But I think the most correct one would be to store the state of a window into a variable.
    Suppose you have a main window, create a member called something like "bool window2Visible". Set it to true when it is open and to false if it isn't. Use signals and slots to check the state.

    You could also test for the validity of a pointer.You might need to set some widget flags here.
    Or, if you only want one instance of one window open at any time, look into singletons.
    ...

Similar Threads

  1. Window Title Text left alignment issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2010, 14:46
  2. Replies: 2
    Last Post: 24th June 2009, 15:38
  3. Window Layout issue.
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2008, 21:46
  4. Double click resize window disable
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 11:35
  5. Replies: 1
    Last Post: 9th February 2007, 09: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.