lakeat
5th January 2013, 05:20
I got an error when running my qt program. (It used to work and can be compiled perfectly before I add this new function void perfectPanel::aaaf in order to do something.) The error message is,
QLayout::parentWidget: A layout can only have another layout as a parent. Segmentation fault (core dumped)
It happens since I was trying to add a new widget to my layout gridLayoutSub_, but layout gridLayoutSub_ is within another layout, let's call it gridLayout_
void perfectPanel::aaaf()
{
// some codes ...
gridLayoutSub_->addWidget(kkk, 6, 0, 1, 1);
}
Anyone knows what's going wrong and how to fix it?
More details: Declarations of these two layouts
In mymainwindow class, there is a dock widget. And in order to customize this dock widget, I wrote a new class called perfectPanel which is a subclass of QWidget, and then in the constructor of this perfectPanel, I have the following codes:
groupBoxA = new QGroupBox(tr("groupBoxA"));
QGridLayout* gridLayoutA = new QGridLayout(groupBoxA);
VBoxLayoutPanel = new QVBoxLayout(this);
VBoxLayoutPanel->addWidget(groupBoxA);
groupBoxA->setLayout(gridLayoutA);
setLayout(VBoxLayoutPanel);
As you can see, gridLayoutA is within another layout VBoxLayoutPanel. And the error I mentioned happens when I try to addWidget to gridLayoutA later in function void perfectPanel::aaaf, during:
gridLayoutA->addWidget(kkk, 6, 0, 1, 1);
The header of perfectPanel class
class perfectPanel : public QWidget
{
Q_OBJECT
public:
explicit perfectPanel(QWidget *parent = 0);
~perfectPanel();
private:
// ...
}
QLayout::parentWidget: A layout can only have another layout as a parent. Segmentation fault (core dumped)
It happens since I was trying to add a new widget to my layout gridLayoutSub_, but layout gridLayoutSub_ is within another layout, let's call it gridLayout_
void perfectPanel::aaaf()
{
// some codes ...
gridLayoutSub_->addWidget(kkk, 6, 0, 1, 1);
}
Anyone knows what's going wrong and how to fix it?
More details: Declarations of these two layouts
In mymainwindow class, there is a dock widget. And in order to customize this dock widget, I wrote a new class called perfectPanel which is a subclass of QWidget, and then in the constructor of this perfectPanel, I have the following codes:
groupBoxA = new QGroupBox(tr("groupBoxA"));
QGridLayout* gridLayoutA = new QGridLayout(groupBoxA);
VBoxLayoutPanel = new QVBoxLayout(this);
VBoxLayoutPanel->addWidget(groupBoxA);
groupBoxA->setLayout(gridLayoutA);
setLayout(VBoxLayoutPanel);
As you can see, gridLayoutA is within another layout VBoxLayoutPanel. And the error I mentioned happens when I try to addWidget to gridLayoutA later in function void perfectPanel::aaaf, during:
gridLayoutA->addWidget(kkk, 6, 0, 1, 1);
The header of perfectPanel class
class perfectPanel : public QWidget
{
Q_OBJECT
public:
explicit perfectPanel(QWidget *parent = 0);
~perfectPanel();
private:
// ...
}