Using 2 or more .ui files together
-
I'm relatively new to QT and am using the designer to reduce the slope of the learning curve.
My question, now is about using two windows..(as an example.. Help->About)
I already have the main window and the menus, then I made a dialog form by Forms-> Add New.
How do I set it up so that the About action will be linked to the showing of the other dialog window? -
Something like this:
@....
connect(ui->actionAbout,SIGNAL(clicked()),this,SLOT(showAbout());
...
void MainWindow::showAbout()
{
AboutDialog *about = new AboutDialog(this);
about->exec();// or you can use this also
// QMessageBox::about(this, tr("Title"),tr("About"));
}@edit: fixed, sorry for the wrong tip
-
General course of action:
Create a slot function in your main window.
@class MyClass : public QMainWindow {
...
public slots:
void showAbout();
...
@In that function, create the widget or dialog
@void MyClass::showAbout()
{
AboutDialog *dlg = new AboutDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
dlg->open(); // window modal
}
@in the appropriate place, possibly constructor or using designer, connect the menu action clicked() signal to your slot.
@connect(ui->actionAbout, SIGNAL(clicked()), this, SLOT(showAbout()));@I don't really know how to do that last step with designer anymore :P.
-
[quote author="HuXiKa" date="1308144526"]Something like this:
@void MainWindow::showAbout()
{
aboutDialog about;
about.show();
}@
[/quote]
This particular piece of code will not work as expected, because the dialog is destroyed when you go out of scope. about.exec() would be the function of choice in this case (the other solution is "somewhat safer":http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/ though). -
[quote author="Franzk" date="1308144781"]
I don't really know how to do that last step with designer anymore :P.[/quote]It's a little bit complicated, but my method is:
1: F4-> slot mode, try to create a connection between something and the MainWindow,
2: in the pop-up window add your slot to the MainWindow,
3: create your normal signal-slot connection (in the bottom right corner).But I'm sure there is an easier way to do this :)
-
I followed the following steps..point out where it goes wrong:
- Created a new .ui file...(The name of the Object being AboutDialog)
2.Followed Franzk's first post.
<AboutDialog is not recognized and
the slot is not accessible from designer>
- Created a new .ui file...(The name of the Object being AboutDialog)
-
There is only the .ui file for that...I created the dialog with the designer..
How do I include ui files?