Incorrect of a widget addition
-
Hi. Why this code is not correct?
I get the warning:
Warning: QLayout: Attempting to add QLayout "to QDialog "QDialog", which already has a layoutQWidget *w = new QWidget; QDialog *dlg = new QDialog; QVBoxLayout *lay = new QVBoxLayout; dlg->setLayout(lay); lay->addWidget(w);Surely, I know QDialog has a layout. But when I tried to add into this layout widget, I get Segmentation Fault.
QWidget *w = new QWidget; QDialog *dlg = new QDialog; dlg->layout()->addWidget(w); -
@Evgeny-Siberia said in Incorrect of a widget addition:
_settingsForm
Shouldn't this be
w?QDialog has no layout by default. You must be setting another one somewhere else.
-
Hi. Why this code is not correct?
I get the warning:
Warning: QLayout: Attempting to add QLayout "to QDialog "QDialog", which already has a layoutQWidget *w = new QWidget; QDialog *dlg = new QDialog; QVBoxLayout *lay = new QVBoxLayout; dlg->setLayout(lay); lay->addWidget(w);Surely, I know QDialog has a layout. But when I tried to add into this layout widget, I get Segmentation Fault.
QWidget *w = new QWidget; QDialog *dlg = new QDialog; dlg->layout()->addWidget(w);layout() pointer should be nullptr initialized, so check against it and do it appropriately.
QWidget *w = new QWidget; QDialog *dlg = new QDialog; if(dlg->layout()){ dlg->layout()->addWidget(w); }else{ QVBoxLayout *lay = new QVBoxLayout; lay->addWidget(w); dlg->setLayout(lay); }