Results 1 to 14 of 14

Thread: A problem with MDI windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: A problem with MDI windows

    I need to be able to open the new mdiwindow through a button click on the mdi child window.

    So basically I have:

    Mainwindow
    |
    mdichildwindow1 (this I can create from the Mainwindow using ui->mdiArea->addSubWindow...)

    And I need to create mdichildwindow2 by pressing a button on mdichildwindow1 so it will look like this

    Mainwindow
    |......... |
    mdi1.. mdi2..

    How would I go about opening it from the main window?

    Should I create a function or something in the mainwindow, and then somehow call it with the necessary parameters from the child window?

    How would I go about doing that?

    Thanks

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

    Default Re: A problem with MDI windows

    Quote Originally Posted by Datakim View Post
    I need to be able to open the new mdiwindow through a button click on the mdi child window.
    That doesn't mean the code for that needs to be in the child window class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: A problem with MDI windows

    But how do I execute the code from the mainwindow

    So basically I have:
    mainmdiwindow
    and
    mdichild1

    and I have a button on the mdichild1

    I can create the mdichild1 from a button in mainmdiwindow just fine. But now I need to be able to create mdichild2 from a button in mdichild1 in such a way that it appears in the same mdi area as mdichild1.

    What kind of code do I need to place on the button clicked event in the mdichild1 in order to call say a function on mainmdiwindow to create a mdichild2 under mainmdiwindow

    Sorry if I am asking idiotic questions, but I am very much a newbie and just learning.

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

    Default Re: A problem with MDI windows

    Quote Originally Posted by Datakim View Post
    But how do I execute the code from the mainwindow
    For example you can use signals and slots. Also you can always pass a pointer to one object to another object that needs to access its functions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Datakim (15th April 2012)

  6. #5
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: A problem with MDI windows

    Ahh. I figured out the problem.

    When I was creating the mdichild window, I did not pass a (this) pointer parameter, but I still tried to use the childwindows parent value to try and access the mainmdiwindow. Which was ofcourse a default of 0 since I did not send a pointer.

    I feel like an idiot now

    I managed to get it to work now. Thank you very much for your help!

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

    Default Re: A problem with MDI windows

    You shouldn't be accessing the main window through the QObject::parent() method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: A problem with MDI windows

    Quote Originally Posted by wysota View Post
    You shouldn't be accessing the main window through the QObject::parent() method.
    Why not?

    This is what I am doing now.

    I create a new window in the mainwindow with:
    Qt Code:
    1. jasenSiirto *jassiir = new jasenSiirto(this);
    2. jassiir->setWindowTitle("Jäsenten siirto");
    3. ui->mdiArea->addSubWindow(jassiir, Qt::SubWindow);
    4. jassiir->show();
    To copy to clipboard, switch view to plain text mode 

    And then used the parent value from the created window constructor

    Qt Code:
    1. jasenSiirto::jasenSiirto(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::jasenSiirto)
    To copy to clipboard, switch view to plain text mode 

    I then managed to use the signaling system to contact the mainwindow and get it to create another mdichild window.

    It seemed to work atleast. Are there some stability/security/other problems with this approach? How should I do it then?

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

    Default Re: A problem with MDI windows

    Ah, you're doing it this way... Splitting the code into two parts (one for creating the dialog, one for adding it to the mdi area) doesn't make much sense. And you don't need to set the parent yourself since addSubWindow will reparent the widget to the mdi area.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: A problem with MDI windows

    Quote Originally Posted by wysota View Post
    Ah, you're doing it this way... Splitting the code into two parts (one for creating the dialog, one for adding it to the mdi area) doesn't make much sense. And you don't need to set the parent yourself since addSubWindow will reparent the widget to the mdi area.
    Can you give an example or point to somewhere where there is one, for a way to do it that makes sense?

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

    Default Re: A problem with MDI windows

    The simplest solution I can think of right now is to emit a signal from the child window that the user requests a new window to be opened and connect that signal to a slot in the main window that will open the new window. Then the complete code can be in one place in the main window as you can open the first child window using the exact same slot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Windows to Linux Problem
    By thehilmisu in forum Newbie
    Replies: 2
    Last Post: 22nd December 2011, 09:12
  2. Replies: 19
    Last Post: 3rd April 2009, 23:17
  3. Problem with linking QT at windows.
    By zygmunt in forum Installation and Deployment
    Replies: 1
    Last Post: 21st October 2008, 21:53
  4. problem with Qt/ Windows--pls help
    By swamyonline in forum Installation and Deployment
    Replies: 8
    Last Post: 7th July 2008, 20:39
  5. Printing problem in windows
    By joseph in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2007, 08:04

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.