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:
Code:
void MainWindow::on_actionQuit_triggered()
{
}
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
Re: Quit action in MainWindow
Code:
void MainWindow::on_actionQuit_triggered()
{
close();
}
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.
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.
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
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:
Code:
void MainWindow::on_push_enter_clicked()
{
KeyDialog dialog(this);
//here I would set the text
dialog.exec();
}
Thanks, this is probably also easy...
Backslash
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:
Code:
void MainWindow::on_push_enter_clicked() {
KeyDialog dialog(this, "text");
dialog.exec();
}
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
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.
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