Results 1 to 5 of 5

Thread: How do I replace a widget?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default How do I replace a widget?

    Hi!

    I have a GLWidget that shows a 3d scene. When I open a file with a scene in, I need to replace that GLwidget with a new GLwidget with the loaded scene. The problem is that the program spits out a lot of exceptions when I close the program. So I suppose that the widget holding the GLWidget still tries to destroy the old GLWidget when I close the program. I'll spare you the long list of messages, but it starts with ***glibc detected*** double free or corruption.
    Is there any way to solve this?

    This is my attempt to do this:
    Qt Code:
    1. /*
    2.   canvas is the GLWidget holding the 3d scene.
    3.   */
    4. mainLayout->removeWidget ( canvas );
    5. canvas->hide ( );
    6. canvas->setParent ( NULL )
    7. delete canvas;
    8.  
    9. /*
    10.   Creates the new GLCanvas containing the new loaded scene....
    11.  
    12.   */
    13. canvas = new GLCanvas ( newScene, this );
    14. mainLayout->addWidget ( canvas );
    To copy to clipboard, switch view to plain text mode 

    hope I've explained the problem in a understandable way...
    thanks for reading
    pir

  2. #2
    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: How do I replace a widget?

    Why do you have to replace the widget? Maybe you could make the widget able to handle both scenes and just replace the scene and not the widget?

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: How do I replace a widget?

    A good point.
    But what if I later on want to be able to have access to the old scene from another widget. In that case, it makes it a bit more complex to insert the new information in the already existing GLWidget. Because then I would use the old memory address and pointers pointing to this adress in belief that it contains the old information would be suprised.

    But I've found a solution to the problem.

    I've forgot something very important in my question. Was to tired and anoyed:

    the GLWidget class called GLCanvas has two parents, GLWidget and Scene. Where class Scene is a class with all the 3d rendering stuff. So the solution was simply to create a new GLCanvas and insert the loaded scene information in it by calling Scene:perator=(const Scene&)... I tried to do this at contruction of the GLCanvas, but there seems to be something I don't know about Qt and copy constructors and operator=. Because it didn't work if I passed the loaded scene into the constructor...

    thanks
    pir

  4. #4
    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: How do I replace a widget?

    Quote Originally Posted by pir
    A good point.
    But what if I later on want to be able to have access to the old scene from another widget.
    But you are deleting the widget so how do you want to access it later?

    In that case, it makes it a bit more complex to insert the new information in the already existing GLWidget. Because then I would use the old memory address and pointers pointing to this adress in belief that it contains the old information would be suprised.
    I don't really... understand...

    Maybe all you need is QStackedWidget?

  5. #5
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: How do I replace a widget?

    Yes, at the current implementation I am deleting the old scene. But I think there may come up situations where I need the old scene in future versions of the program. If that is the case, I only need to erase the delete command. But I'm not sure about what kind of situation that would be, but I thought that if it didn't cost too much effort do this, it could be a nice way to handle it.

    Maybe if I have several widgets displaying the same scene but from different cameras and I for some reason want to open a new scene in one of the widgets and still having the old scene in the others... sure there are a lot of ways to solve this. But I think that, by doing this, I maybe have more flexibility. And since I managed to do this, it's was easier to implement than changing to a stacked widget or something similar.


    thanks
    pir

Similar Threads

  1. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 07:57
  2. Replies: 4
    Last Post: 24th March 2006, 23:50
  3. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16
  4. advanced split widget
    By vitaly in forum Qt Programming
    Replies: 10
    Last Post: 24th January 2006, 21:00

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.