Results 1 to 14 of 14

Thread: Call MainWindow through QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Exclamation Call MainWindow through QDialog

    Hi.

    Some say I know how do I show a MainWindow starting from a QDialog?


    Regards,
    Daniel Sousa

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call MainWindow through QDialog

    If you know then please share

    If you don't know, please elaborate what you mean.

  3. #3
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Call MainWindow through QDialog

    Quote Originally Posted by Spitfire View Post
    If you know then please share

    If you don't know, please elaborate what you mean.
    Sorry but I can not write very well English.

    I want to know how a call MainWindow when I click a button on a QDialog.

    regards,
    Daniel Sousa

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call MainWindow through QDialog

    Do you have both dialog and main window and you just want to show main window over the dialog?

    Is the main window hidden?
    Do you want to create main window on button press?
    Is the dialog modal?

    Od maybe you want to call a method in main window class when some button in the dialog is pressed?

    English may not be your mother tongue, but google is your friend.
    Write best description you can in your language and then translate it to english using google.

    From what you said I can't figure out what you need.
    Sorry :/

  5. #5
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Call MainWindow through QDialog

    Quote Originally Posted by Spitfire View Post
    Do you have both dialog and main window and you just want to show main window over the dialog?

    Is the main window hidden?
    Do you want to create main window on button press?
    Is the dialog modal?

    Od maybe you want to call a method in main window class when some button in the dialog is pressed?

    English may not be your mother tongue, but google is your friend.
    Write best description you can in your language and then translate it to english using google.

    From what you said I can't figure out what you need.
    Sorry :/
    I want to start the application and opens a QDialog, after I click a button create a MainWindow.

  6. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call MainWindow through QDialog

    If you can write main window, you should be able to write code below:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. MagicDialog d( this );
    6. if( d.exec() )
    7. {
    8. MainWindow w;
    9. w.show();
    10. return a.exec();
    11. }
    12. return -1;
    13. }
    To copy to clipboard, switch view to plain text mode 
    In MagicDialog connect whatever button you want to accept() slot to show main window, connect other button to reject() to terminate the application.

  7. #7
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Call MainWindow through QDialog

    Quote Originally Posted by Spitfire View Post
    If you can write main window, you should be able to write code below:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. MagicDialog d( this );
    6. if( d.exec() )
    7. {
    8. MainWindow w;
    9. w.show();
    10. return a.exec();
    11. }
    12. return -1;
    13. }
    To copy to clipboard, switch view to plain text mode 
    In MagicDialog connect whatever button you want to accept() slot to show main window, connect other button to reject() to terminate the application.
    I tried the code and you said to me the following error:

    / Users/danielsousa/Qt/Interface2-build/../Interface2/main.cpp: 8: error: invalid use of 'this' in non-member function

  8. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call MainWindow through QDialog

    D-oh, no need for parent there, just remove it.
    Should be obvious.

  9. #9
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Call MainWindow through QDialog

    Quote Originally Posted by Spitfire View Post
    D-oh, no need for parent there, just remove it.
    Should be obvious.
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    Inicio d();
    if(d.exec()){


    MainWindow w;
    w.show();

    return a.exec();
    }
    //Inicio w;
    //w.show();
    return -1;
    }

    I like the code on top and me the error: /Users/danielsousa/Qt/Interface2-build/../Interface2/main.cpp:10: error: request for member 'exec' in 'd', which is of non-class type 'Inicio ()()'

  10. #10
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call MainWindow through QDialog

    So, why you're talking about dialog when you're not using a dialog?
    Is your 'dialog' a QWidget?

    Use QDialog as a base class.

    And read the docummentation for QDialog.

  11. #11
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Call MainWindow through QDialog

    Quote Originally Posted by Spitfire View Post
    So, why you're talking about dialog when you're not using a dialog?
    Is your 'dialog' a QWidget?

    Use QDialog as a base class.

    And read the docummentation for QDialog.
    But I'm using a QDialog. I want to click a button that a QDialog and open a MainWindow

Similar Threads

  1. size of Mainwindow Shrinks when i call it from a Dialog
    By ranjit.kadam in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2011, 07:17
  2. How to Call a QDialog in QMainWindow
    By mcht_z in forum Newbie
    Replies: 2
    Last Post: 13th April 2011, 06:43
  3. Replies: 1
    Last Post: 12th April 2011, 09:53
  4. How to call a dialog from a mainwindow
    By luiz4um in forum Qt Programming
    Replies: 26
    Last Post: 29th June 2010, 10:41
  5. QDialog, Mainwindow
    By triperzz in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 06:59

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.