Results 1 to 8 of 8

Thread: How to delete ui member?

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to delete ui member?

    So this is the situation: I have created my own custom widget, and it uses 2 separate forms, designed in Designer and defined in the private section of the header file. When I switch between the two forms, I have to delete the objects and layout in the other form, otherwise I get a mess.

    I use something like myForm.setupUi() and lster myForm2.setupUi(), but doing that causes problems. So I need to somehow delete the objects created by the setupUi() function. I tried qDeleteAll(children()) but that deleted everything in the widget, not just in the UI part, and I don't want that.

    Basically I want to undo the operations of setupUi(). Any ideas? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to delete ui member?

    Quote Originally Posted by codeslicer View Post
    So this is the situation: I have created my own custom widget, and it uses 2 separate forms, designed in Designer and defined in the private section of the header file. When I switch between the two forms, I have to delete the objects and layout in the other form, otherwise I get a mess.
    What kind of mess?

  3. #3
    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: How to delete ui member?

    The easiest way will be to use separate widgets instead of "this". Using QStackedWidget is also one option.
    J-P Nurmi

  4. #4
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delete ui member?

    Thanks for answering, but I meant something else I guess...

    Check post 20 on this thread: http://www.qtcentre.org/forum/f-qt-p...ins-12013.html

    You told me I have to delete the old objects on the form, that's what I have to do. However doing qDeleteAll(children()) deletes everything in that class.

    Anyways, thanks in advance! ~codeslicer

  5. #5
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delete ui member?

    *BUMP*

    jpn if only you could help

  6. #6
    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: How to delete ui member?

    Quote Originally Posted by codeslicer View Post
    However doing qDeleteAll(children()) deletes everything in that class.
    This is exactly why I suggested introducing an additional layer. Just allocate a plain wrapper QWidget on which you load the designed form. Then you can simply delete that wrapper widget whenever you want.
    J-P Nurmi

  7. #7
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delete ui member?

    Sorry for the late reply...

    The problem is that I want to use 2 separate, different forms in the same class.

    I can't create a "wrapper" widget, is there any way of excluding some objects from the children() list? If I use qDeleteAll(children()) then I want to prevent some of the objects from getting deleted, how would I do that? Can I treat it as a regular QList and use the negative (-) operator to remove certain objects? How would I do that? Would this work:

    Qt Code:
    1. QObject myPermanentObject;
    2. QObject myPermanentObject2;
    3. ...
    4. QObjectList childrenList = children();
    5. childrenList.removeAt(indexOf(myPermanentObject));
    6. childrenList.removeAt(indexOf(myPermanentObject2));
    7. ...
    8. qDeleteAll(childrenList);
    To copy to clipboard, switch view to plain text mode 

    Thanks

  8. #8
    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: How to delete ui member?

    Quote Originally Posted by codeslicer View Post
    The problem is that I want to use 2 separate, different forms in the same class.

    I can't create a "wrapper" widget
    Why would that be?

    Qt Code:
    1. {
    2. // setting up a common layout
    3. layout = new QVBoxLayout(this);
    4. layout->setMargin(0);
    5.  
    6. // creating common actions (which are not deleted when changing the form)
    7. QAction* action = new QAction(this);
    8. ...
    9. }
    10.  
    11. {
    12. // setting up form A
    13. wrapper = new QWidget(this);
    14. oneUi.setupUi(wrapper);
    15. layout->addWidget(wrapper);
    16. }
    17.  
    18. {
    19. // setting up form B
    20. wrapper = new QWidget(this);
    21. anotherUi.setupUi(wrapper);
    22. layout->addWidget(wrapper);
    23. }
    24.  
    25. {
    26. // cleaning up either form
    27. delete wrapper;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Or just throw the whole complex idea away and start using QStackedWidget.
    J-P Nurmi

Similar Threads

  1. problem with forward declaration
    By MarkoSan in forum General Programming
    Replies: 14
    Last Post: 6th January 2008, 21:45
  2. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  3. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.