Results 1 to 8 of 8

Thread: Layout Managers???

  1. #1
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    MacOS X Windows

    Default Layout Managers???

    Hello again,

    Does ANYBODY know anything about layout managers??? I haven't gotten any information here and there's nothing in the documentation or Qt book (using 3.3.4).

    In the docs it shows us card.cpp and card.h which is their own layout manager. I implemented it and it crashes. Great. However, it doesn't crash anywhere in visible code, but it's definitely the manager that's crashing. I don't even know if I'm calling it right because there's no mention of how to even use it.

    How do I add a widget??? Widgets don't inherit qlayout and layouts don't inherit qwidget, so how is this thing supposed to work?
    Qt Code:
    1. HomeLayout->addItem( (QWidget *) qLineEdit1 );
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. HomeLayout->addItem( (QWidgetItem *) qLineEdit1 );
    To copy to clipboard, switch view to plain text mode 

    Please help, as this is NOT ( )in the documentation and I don't have a clue how it's supposed to work. NOTHING Works With This!

    THANKS!
    Jay

  2. #2
    Join Date
    Jan 2006
    Location
    New Zealand
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Layout Managers???

    You don't use the QLayout directly (You can't even, as it's an abstract base class). Use a QBoxLayout or a QGridLayout.

    Both have addWidget() and addLayout() methods.

    Docs:
    http://doc.trolltech.com/3.3/qlayout.html
    http://doc.trolltech.com/3.3/qgridlayout.html
    http://doc.trolltech.com/3.3/qboxlayout.html

  3. #3
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    MacOS X Windows

    Default Re: Layout Managers???

    I'm just implementing the custom layout manager as in this example.

    http://doc.trolltech.com/3.0/customlayout-example.html

    Unfortunately I haven't been able to get it to run without crashing. There's nothing in this example which states how to set it up and nothing I've tried works. I think it has something to do with QLayoutItem vs. QWidgetItem and such, but who know. Do you know how to use this custom example?

    Has anyone, ANYONE gotten this example to work?

    Thanks!
    Jay

  4. #4
    Join Date
    Jan 2006
    Location
    New Zealand
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Layout Managers???

    You can't run the example itself? Or code you've tried to write based off of it?

    The example compiles and runs for me without complaint (qt 3.3.4, gcc 4.0.2)


    If it's your code, can you show more of what you're trying to do?

  5. #5
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    MacOS X Windows

    Default Re: Layout Managers???

    Their code compiles without problems, but it continually crashes, usually within the bowels of the minimumSizeHint or sizeHint, but it's impossible to find (using vc++). I haven't modified it at all. The only code of mine that's relevant I posted above where I call it using a QLineEdit, or rather 2 of them. I renamed CardLayout to HomeLayout, and that's the only modification I made to their code.

    frButtons is just a frame that contains the 2 qlineedits.

    Qt Code:
    1. HomeLayout1 = new HomeLayout((QWidget *)frButtons, 6);
    2. leA = new QLineEdit( frButtons, "lineEditA" );
    3. leB = new QLineEdit( frButtons, "lineEditB" );
    4.  
    5. HomeLayout1->addItem( leA );
    6. HomeLayout1->addItem( leB );
    To copy to clipboard, switch view to plain text mode 
    This doesn't compile, I get error: error C2664: 'HomeLayout::addItem' : cannot convert parameter 1 from 'QLineEdit *' to 'QLayoutItem *'

    So, I tried casting leA and leB to ('QLayoutItem *) in the call to addItem which does compile, and then crashes on running, somewhere within minimumSizeHint or sizeHint (access violation).

    How do you call addItem? Can you show me what you did for the testing code?

    Thank you for the help,
    Jay

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Layout Managers???

    So the code crashes not because layouts are bad, but because you cast a pointer of one class to another class, which it doesn't inherit, which is a "no no".

    Try:

    Qt Code:
    1. QLayoutItem *lit = new QWidgetItem(le1);
    To copy to clipboard, switch view to plain text mode 

    At least types will match

  7. #7
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    MacOS X Windows

    Default Re: Layout Managers???

    Yeah, I tried that too. I'm out of ideas of what to try.

    I'd love to get some very simple test code in which this layout works with a few widgets. Any help there

    Thank you!

    Jay

  8. #8
    Join Date
    Jan 2006
    Location
    New Zealand
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Layout Managers???

    What if you use the add() method, rather than the addItem() method to add your widgets?

    That's what the example uses. It's defined in QLayout, and takes a QWidget as a parameter.

Similar Threads

  1. Custom Widgets and layout managers...
    By TemporalBeing in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2009, 13:48
  2. Replies: 3
    Last Post: 27th November 2008, 23:57
  3. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:36
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  5. Avoiding leaks with layout managers
    By invictus in forum Newbie
    Replies: 6
    Last Post: 21st March 2007, 22:01

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.