Results 1 to 10 of 10

Thread: Quit action in MainWindow

  1. #1
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Question Quit action in MainWindow

    I'm attempting to close a form when quit is selected in the tool bar. The form has an action called actionQuit which is written as such in the MainWindow.cpp file:

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

    How do I actually call the form to close inside of this? do I reference it as "ui.something"? Sorry if this is a seemingly simple question, I just cannot find the answer on my own.

    Thank you,
    Backslash

  2. #2
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Quit action in MainWindow

    Qt Code:
    1. void MainWindow::on_actionQuit_triggered()
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 
    Excuse me for English, I from Russia

  3. The following user says thank you to ufo-vl for this useful post:

    Backslash (31st July 2007)

  4. #3
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Quit action in MainWindow

    Yes, or in the constructor:

    connect(actionQuit, SIGNAL(triggered()), this, SLOT(close()));

    You don't actually need another function. This is textbook signals/slots.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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

    Backslash (31st July 2007)

  6. #4
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Quit action in MainWindow

    Yes, as another newbie I can attest to the fact that Qt's signals and slots are one of its most powerful features, and will make your life so much easier once you start using them.

  7. The following user says thank you to WinchellChung for this useful post:

    Backslash (31st July 2007)

  8. #5
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Quit action in MainWindow

    Wow, I guess the problem was...I never thought it could be that easy. Thanks very much for the quick replies.

    Thanks Again,
    Backslash

  9. #6
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Quit action in MainWindow

    I have another question that is along the same lines...

    I want to directly set the text for a widget on a second form when a button is pressed on the first form, can I do this? I'm trying to use auto-connect so I have a button's clicked signal connected here:

    Qt Code:
    1. void MainWindow::on_push_enter_clicked()
    2. {
    3. KeyDialog dialog(this);
    4. //here I would set the text
    5. dialog.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thanks, this is probably also easy...
    Backslash

  10. #7
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Quit action in MainWindow

    If you created the KeyDialog yourself, you can add a public function, or an option in the constructor, to change that text. It would look something like this when called:

    Qt Code:
    1. void MainWindow::on_push_enter_clicked() {
    2. KeyDialog dialog(this, "text");
    3. dialog.exec();
    4. }
    To copy to clipboard, switch view to plain text mode 
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  11. The following user says thank you to Michiel for this useful post:

    Backslash (31st July 2007)

  12. #8
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Quit action in MainWindow

    Thank you, that makes sense. I'll give it a try...

    While we're on the subject though, Is there there a way to reference widgets on one form from another form?

    Thanks,
    Backslash

  13. #9
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Quit action in MainWindow

    Keep in mind that Qt forms (and all other Qt widgets) are simply C++ classes. As with every C++ class, members that are public are visible from the outside.

    So yes, you can make the widgets public instead of private or protected. But this is considered bad practice, since it breaks encapsulation.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  14. The following user says thank you to Michiel for this useful post:

    Backslash (31st July 2007)

  15. #10
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: Quit action in MainWindow

    Thanks again for your patient explanation of what should be simple concepts...I guess I wasn't thinking of it the way I should have been (as classes) and it now makes perfect sense.

    Thanks,
    Backslash

Similar Threads

  1. No action checked in an exclusive action group
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 07:19

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.