Results 1 to 7 of 7

Thread: A bug of QLayout

  1. #1
    Join Date
    Feb 2006
    Posts
    11
    Thanks
    1

    Default A bug of QLayout ?

    Hi,
    I just find a assert failure when I use QLayout. I want know is this a bug of QLayout.
    The QLayout has a constructor like this, which need a parent of QWdiget
    Qt Code:
    1. QLayout::QLayoutQWidget *parent)
    2. : QObject(*new QLayoutPrivate, parent)
    3. {
    4. if (!parent)
    5. return;
    6. parent->setLayout(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    But in the code of QLayout:arentWidget() (line 6), it trys to cast the parent to QLayout
    Qt Code:
    1. QWidget *QLayout::parentWidget() const
    2. {
    3. Q_D(const QLayout);
    4. if (!d->topLevel) {
    5. if (parent()) {
    6. QLayout *parentLayout = ::qobject_cast<QLayout*>(parent());
    7. Q_ASSERT(parentLayout);
    8. return parentLayout->parentWidget();
    9. } else {
    10. return 0;
    11. }
    12. } else {
    13. Q_ASSERT(parent() && parent()->isWidgetType());
    14. return static_cast<QWidget *>(parent());
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    certainly, cast from QWidget* to QLayout* will failled, and the successed assertion will failed. Is this a bug or anything I don't know?
    Thanks for your help!
    Last edited by cocalele; 24th April 2006 at 07:25.

  2. #2
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: A bug of QLayout

    Could you provide a minimal example that reproduces the problem? I don't think there's a bug (the parent constructor argument and parent() are different) but it's hard to tell without some code to reproduce the failed assertion.

  3. #3
    Join Date
    Feb 2006
    Posts
    11
    Thanks
    1

    Default Re: A bug of QLayout

    here's some code reproduce the error
    Qt Code:
    1. HelloQt::HelloQt(QWidget *parent, Qt::WFlags flags)
    2. : QDialog(parent, flags)
    3. {
    4. QHBoxLayout *topMostLayout = new QHBoxLayout(this);
    5.  
    6. //QVBoxLayout *subLayout = new QVBoxLayout(this); //addLayout will fail
    7. QVBoxLayout *subLayout = new QVBoxLayout(); //It's OK
    8.  
    9. topMostLayout->addLayout(subLayout);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by cocalele; 25th April 2006 at 02:57.

  4. #4
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: A bug of QLayout

    I mean a minimal complete program that I could build to reproduce what you're seeing.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: A bug of QLayout

    Quote Originally Posted by cocalele
    Qt Code:
    1. QHBoxLayout *topMostLayout = new QHBoxLayout(this);
    2. QVBoxLayout *subLayout = new QVBoxLayout(this); //addLayout will fail
    To copy to clipboard, switch view to plain text mode 
    This is non-sense. Passing a parent widget to layout constructor is same than setting the layout as widget's layout. So what the code above does is it tries to set 2 different layouts one after another to a same widget.

    Attempting to add QLayout "" to QDialog "", which already has a layout.
    Anyhow, all it does for me is showing the warning. No assertion fails for me with Qt 4.1.2..
    Which version are you using?

    Edit: Check this task tracker entry.
    J-P Nurmi

  6. #6
    Join Date
    Feb 2006
    Posts
    11
    Thanks
    1

    Default Re: A bug of QLayout

    Quote Originally Posted by dimitri
    I mean a minimal complete program that I could build to reproduce what you're seeing.
    Thanks for your help! I have attached my whole test code in HelloQt.zip.

    The assert fail is not in the constructor of subLayout, but in the code add sublayout to the topmost layout.

    I use Qt4.1.0
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: A bug of QLayout

    Did you check the task tracker entry link I provided? This has already been fixed in Qt 4.1.1.
    Changes 4.1.1: "QLayout: Warn instead of crash when adding two layouts to a widget."

    So consider updating to the newest Qt.
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    cocalele (27th April 2006)

Similar Threads

  1. whether Qcanvas objects be added in QLayout
    By Amrita Singh in forum Newbie
    Replies: 1
    Last Post: 25th February 2009, 09:55
  2. QLayout: different SizeConstraints for width and height?
    By PhilippB in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2009, 16:33
  3. QLayout on hidden window
    By benacler in forum Qt Programming
    Replies: 0
    Last Post: 2nd September 2008, 18:04
  4. QLayout update size signal
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2008, 11:24
  5. custom QLayout help
    By Micawber in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2007, 21:44

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.