Yes. I mean static as in it gets allocated when the program starts and remains for the life of the program so that irregardless of whether the dialog box is open or closed the contained static variables retain their last set state.
Actually I meant upon the declaration of the dialog box, not the beginning of the program.
No, I don't think you mean "static" in any C++ sense at all. The C++ object and its possible visual presence are not related to each other. The member variables in the object do not go away when the visual item is hidden: they only go away when you destroy the object. Here's an example of a dialog that is shown, hidden, and shown again. The value of its text box persists between showings and is available when the dialog is hidden:
#include <QtGui>
{
Q_OBJECT
public:
layout->addWidget(lineEdit);
layout->addWidget(button);
setLayout(layout);
connect(button, SIGNAL(clicked()), SLOT(accept()));
}
return lineEdit->text();
}
private:
};
int main(int argc, char **argv)
{
MyDialog dialog; // dialog object exists
(void) dialog.exec(); // dialog is visible
qDebug() << dialog.getText(); // dialog is not visible but the object still exists
(void) dialog.exec(); // dialog is visible
qDebug() << dialog.getText(); // dialog is not visible but the object still exists
return 0;
}
#include "main.moc"
#include <QtGui>
class MyDialog: public QDialog
{
Q_OBJECT
public:
explicit MyDialog(QWidget *p = 0): QDialog(p) {
QVBoxLayout *layout = new QVBoxLayout(this);
lineEdit = new QLineEdit(this);
QPushButton *button = new QPushButton("Ok", this);
layout->addWidget(lineEdit);
layout->addWidget(button);
setLayout(layout);
connect(button, SIGNAL(clicked()), SLOT(accept()));
}
QString getText() const {
return lineEdit->text();
}
private:
QLineEdit *lineEdit;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyDialog dialog; // dialog object exists
(void) dialog.exec(); // dialog is visible
qDebug() << dialog.getText(); // dialog is not visible but the object still exists
(void) dialog.exec(); // dialog is visible
qDebug() << dialog.getText(); // dialog is not visible but the object still exists
return 0;
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks