Solved Run the initialization everytime you start a dialog
-
Hi, so the title might sound confusing, but here's what I'm trying to figure out.
So every time you start a Qt application, it has an initialization.
Like this (this one's a dialog):Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); }
But there's a problem with that.
It only does it once (on application start), and that's a problem for me.
So, is there a way, when I call a dialog to start, to execute something like this ALL the time? -
@Sucharek
This initialization happens each time a fresh instance of aDialog
is created, rather than at application start time.If you want a freshly initialized instance create one with
Dialog *dialog = new Dialog;
orDialog dialog;
as appropriate, instead of keeping the old instance you had around. -
Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?
-
@Sucharek said in Run the initialization everytime you start a dialog:
Hi @JonB, ok, but can I do this with an already existing dialog (like a class)?
Hi,
It's vague, please explain what you want to do with a real use case.
-
@mpergand, I want to execute a command, when the dialog gets executed.
For more explanation, I'm executing a Qt designer form class. I make a dialog design, give it some functions, but everytime it gets executed, I need to update some variables, ui elements, etc., and I wanna do that everytime I execute it (everytime I do: dialog.exec()) -
@Sucharek
So put your extra initialization code after theui->setupUi(this);
, or in a method you write and call. -
@Sucharek
Hum, not sure to understand you correctly ...If you want to excute something after the dialog is showed, implement a method in that dialog and call it each time you need it.
-
-
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); initialyze(); } Dialog::initialyze() { // initialyzing stuff here } // somewhere in your prog myDialog->initialyze();
-
@Sucharek
Depending on whether you create a newQDialog
each time you show it or you keep one around and re-use it, eitherPut what you want extra after
ui->setupUi(this);
inDialog::Dialog()
.Or do something like:
Dialog::doSomeStuffToTheUi() { ui->doSomething(); } // Outside world caller dialog.doSomeStuffToTheUi(); dialog.exec();
If that does not do what you want, you are either doing something wrong or you are not explaining what this fails to achieve.
-