Results 1 to 5 of 5

Thread: AddSubWindow() doesn't work

  1. #1
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default AddSubWindow() doesn't work

    I have simple MainWindow. MdiArea is in it. I can't create more small mdichild.
    code of MainWindow constructor:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. mdiArea = new QMdiArea;
    7. setCentralWidget(mdiArea);
    8. MdiChild *one = CreateChild();
    9. MdiChild *two = CreateChild();
    10. mdiArea->addSubWindow(one);
    11. mdiArea->addSubWindow(two);
    12.  
    13. connect(ui->actionNew_Document,SIGNAL(triggered()),this,SLOT(CreateNewDocument()));
    14.  
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MdiChild* MainWindow::CreateChild()
    2. {
    3. MdiChild *newChild = new MdiChild;
    4. static int count = 0;
    5.  
    6. newChild->setWindowTitle(QString("%1 - %2").arg(count++).arg("Document"));
    7.  
    8. return newChild;
    9.  
    10. }
    11. void MainWindow::CreateNewDocument()
    12. {
    13. mdiArea->addSubWindow(CreateChild()); //This doesn't work
    14. }
    To copy to clipboard, switch view to plain text mode 

    I commented "mdiArea->addSubWindow(CreateChild());" and added QMessageBox and that worked. so slot function is executed. but can't figure out why addSubWindow doesn't work.

    Capture.JPG

    When I press New Document action,new window doesn't appear.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AddSubWindow() doesn't work

    Have you tried calling show() on the new window?

    Cheers,
    _

  3. #3
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AddSubWindow() doesn't work

    I have tried but window is being immedietly closed as I see. But I can't understand why we need "show" method.
    I haven't call show method here:
    Qt Code:
    1. MdiChild *one = CreateChild();
    2. MdiChild *two = CreateChild();
    3. mdiArea->addSubWindow(one);
    4. mdiArea->addSubWindow(two);
    To copy to clipboard, switch view to plain text mode 

    Code in CreateNewWindow I changed to:
    Qt Code:
    1. void MainWindow::CreateNewDocument()
    2. {
    3. QWidget *xx = new QWidget;
    4. xx->show();
    5. mdiArea->addSubWindow(xx);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But window is dissappeared immedietly and I don't know why.




    P.S Sorry for my English language mistakes. It's my second language.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AddSubWindow() doesn't work

    Quote Originally Posted by Higgs View Post
    I have tried but window is being immedietly closed as I see. But I can't understand why we need "show" method.
    I haven't call show method here:
    Qt Code:
    1. MdiChild *one = CreateChild();
    2. MdiChild *two = CreateChild();
    3. mdiArea->addSubWindow(one);
    4. mdiArea->addSubWindow(two);
    To copy to clipboard, switch view to plain text mode 
    Those are created in the constructor, i.e. before their parent is shown. They get shown when their parent is.
    Windows created afterwards are not automatically shown but when requested.


    Quote Originally Posted by Higgs View Post
    Code in CreateNewWindow I changed to:
    Qt Code:
    1. void MainWindow::CreateNewDocument()
    2. {
    3. QWidget *xx = new QWidget;
    4. xx->show();
    5. mdiArea->addSubWindow(xx);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But window is dissappeared immedietly and I don't know why.
    About about calling show on the MDI window?

    Qt Code:
    1. mdiArea->addSubWindow(CreateChild())->show();
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Higgs View Post
    P.S Sorry for my English language mistakes. It's my second language.
    Not my first language either

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Higgs (16th February 2014)

  6. #5
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AddSubWindow() doesn't work

    Thank you for your reply.
    I was nearly near with solution
    I at first wrote this:
    Qt Code:
    1. mdiArea->addSubWindow(CreateChild()->show());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2013, 06:05
  2. autoScale doesn't work
    By Braunstein in forum Qwt
    Replies: 4
    Last Post: 12th November 2010, 18:22
  3. Q_PROPERTY: the example doesn't work!
    By YaK in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2009, 11:28
  4. Privoxy doesn't work with qt 4.5.1
    By doep in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2009, 10:55
  5. Connection doesn't work
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2007, 12:09

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
  •  
Qt is a trademark of The Qt Company.