how to access layout within another layout in qt
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,
Quote:
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_
Code:
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:
Code:
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:
Code:
gridLayoutA->addWidget(kkk, 6, 0, 1, 1);
The header of perfectPanel class
Code:
class perfectPanel
: public QWidget{
Q_OBJECT
public:
explicit perfectPanel
(QWidget *parent
= 0);
~perfectPanel();
private:
// ...
}
Re: how to access layout within another layout in qt
Everything looks fine, it should just work. I think there somthing else you are doing, which missed to mention.
Re: how to access layout within another layout in qt
I found if I VBoxLayoutPanel.addWidget(), this works. So I am wondering what's the reason that i can only addWidget to parent layout not sub-layout?
Re: how to access layout within another layout in qt
Can you reproduce the warning with a sample project?