camelot
18th June 2013, 12:29
Hey everyone!
I have a very basic question.:o
Usually, I save the pointer to dynamically created objects as members of the class that created it.
However, in Qt there is this automatic dealing with pointers by parent objects.
Can I create a simple label dynamically within the constructor of a selfmade dialog, add it to a layout and this is it?
Some thing like
// constructor of MyDialog class ///////////////////////////////////
MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
QLabel *newLbl = new QLabel("New");
QVBoxLayout *newLay = new QVBoxLayout(this);
newLay.add(newLbl);
}
The QDialog is just an example. It could be also any ordinary class that inherits QWidget.
I was doing it like this for a while and it seemed to work out fine. However, when I used such a selfmade widget within a QTabWidget. All the labels are gone.
Any answer would be appreciated.
David
I have a very basic question.:o
Usually, I save the pointer to dynamically created objects as members of the class that created it.
However, in Qt there is this automatic dealing with pointers by parent objects.
Can I create a simple label dynamically within the constructor of a selfmade dialog, add it to a layout and this is it?
Some thing like
// constructor of MyDialog class ///////////////////////////////////
MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
QLabel *newLbl = new QLabel("New");
QVBoxLayout *newLay = new QVBoxLayout(this);
newLay.add(newLbl);
}
The QDialog is just an example. It could be also any ordinary class that inherits QWidget.
I was doing it like this for a while and it seemed to work out fine. However, when I used such a selfmade widget within a QTabWidget. All the labels are gone.
Any answer would be appreciated.
David