SOLVED: Edit dialog from MainWindow
-
Hello,
I have been trying to set the text of a dialog/designer form that has no class but is called from the MainWindow class when a dialog button is clicked. If it's possible how would you got about it? The slot change_text() sets the content for ap.lineEdit
So far the connector won't call change_text() probably because the dialog has been executed already.@void MainWindow::launch_dialog()
{
QDialog *diag = new QDialog;
Ui::Dialog ap;
ap.setupUi(diag);
diag->setModal(true);
diag->exec();connect(ap.pushButton, SIGNAL(clicked()), this, SLOT(change_text()));
}@
-
You can connect before exec()
-
Hi,
No ap must not be global.What JKSH meant is that you should have moved the connect statement just before calling exec
-
[quote author="Qkato" date="1376606459"]The problem is that declaring another ap inside the slot crashes the application.[/quote]That crash is not caused by the code you posted. It's probably a bug somewhere else that causes memory corruption.
[quote]By global I meant ap should be declared inside the MainWindow class declaration not outside.[/quote]Yes, that's what you need to do. The correct term is "member variable", not "global".
[quote author="Qkato" date="1376519112"]
@
void MainWindow::launch_dialog()
{
QDialog *diag = new QDialog;
Ui::Dialog ap;
ap.setupUi(diag);
diag->setModal(true);
diag->exec();...
}
@
[/quote]Your original code has a memory leak -- diag is never deleted. Make sure you clean up properly.