(新建窗口)
Add New.. Qt – Qt Designer Form Class
Need to include newform.h in mainwindow.cpp file where has slot to open this new window;
Add "extern newDialog *newdialog" in mainwindow.cpp;
Add "newDialog *newdialog" in newwindow.cpp;
Then, in click-button which open new window slot, add:
Add New.. Qt – Qt Designer Form Class
Need to include newform.h in mainwindow.cpp file where has slot to open this new window;
Add "extern newDialog *newdialog" in mainwindow.cpp;
Add "newDialog *newdialog" in newwindow.cpp;
Then, in click-button which open new window slot, add:
void MainWindow::on_pushButton_clicked()
{
if (!newdialog)
newdialog = new newDialog (NULL);
newdialog->exec();
}
The above method creates dialog in heap, so when i click close(), i don't delete it from memory. To close dialog or window completely, the code needs to be changed as:
void MainWindow::on_pushButton_clicked()
{
newDialog newdialog(NULL);
newdialog.exec();
}
{
newDialog newdialog(NULL);
newdialog.exec();
}
we can not use:
cyclescrdialog.show();
show() does not block, so you'll only see a quick flash of your dialog, as it'll be destroyed immediately after calling show() ( when exiting the method ). Using exec() blocks until dialog is closed by the user.
if create new a window/dialog by using code, and did not pre-create window/dialog from “add new.. QT Designer form class”, the new window/dialog may be no shows on the top. This is because that the new window/dialog does not have a parent window/dialog. In order to make sure the new window/dialog shows on the top, use “add new.. QT Designer form class” create a new window/dialog first.
No comments:
Post a Comment