Results 1 to 4 of 4

Thread: how to access layout within another layout in qt

  1. #1
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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,

    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_

    Qt Code:
    1. void perfectPanel::aaaf()
    2. {
    3. // some codes ...
    4. gridLayoutSub_->addWidget(kkk, 6, 0, 1, 1);
    5. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. groupBoxA = new QGroupBox(tr("groupBoxA"));
    2. QGridLayout* gridLayoutA = new QGridLayout(groupBoxA);
    3.  
    4. VBoxLayoutPanel = new QVBoxLayout(this);
    5. VBoxLayoutPanel->addWidget(groupBoxA);
    6.  
    7. groupBoxA->setLayout(gridLayoutA);
    8. setLayout(VBoxLayoutPanel);
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. gridLayoutA->addWidget(kkk, 6, 0, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    The header of perfectPanel class

    Qt Code:
    1. class perfectPanel : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. explicit perfectPanel(QWidget *parent = 0);
    8. ~perfectPanel();
    9.  
    10. private:
    11. // ...
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to access layout within another layout in qt

    Can you reproduce the warning with a sample project?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 6
    Last Post: 13th February 2011, 23:06
  2. Hiding Layout item - Layout does not use available space
    By Asperamanca in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2011, 09:51
  3. Replies: 0
    Last Post: 12th December 2010, 05:09
  4. Replies: 0
    Last Post: 25th May 2009, 10:00
  5. Replies: 7
    Last Post: 15th June 2007, 16:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.