Results 1 to 4 of 4

Thread: Problem in adding Widget to a QGrasphicsScene

  1. #1
    Join Date
    Jan 2009
    Posts
    12
    Qt products
    Qt4

    Default Problem in adding Widget to a QGrasphicsScene

    hi,
    I have designed a widget outside my project which has a widget.cpp, widget.h, widget.ui files now i have added these all files to my project, now i want to display this widget in my scene, so i have created a widget class object.

    Qt Code:
    1. Widget *wid;
    To copy to clipboard, switch view to plain text mode 

    and used addWidget() method of QGraphicsScene class to add it to my widget.

    Qt Code:
    1. scene.addWidget(wid,Qt::Widget);
    To copy to clipboard, switch view to plain text mode 

    but i am not able to add it, my application not at all starting, error is "application closed unexpectedly"
    How can add a .ui form to a scene.

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

    Default Re: Problem in adding Widget to a QGrasphicsScene

    You have not created a widget class object. You have created a variable holding an address of such object but the object doesn't exist. You need to create it using the "new" operator. This is a basic C/C++ knowledge, you know...

  3. #3
    Join Date
    Jan 2009
    Posts
    12
    Qt products
    Qt4

    Default Re: Problem in adding Widget to a QGrasphicsScene

    I have tried even that way, but its not coming. is my approach correct can we add it like that, I mean by creating a class object of Widget class and adding it to the scene.

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

    Default Re: Problem in adding Widget to a QGrasphicsScene

    Yes, but as for now you are accessing an invalid pointer If you stop doing that and in turn assign a proper widget object to the pointer, it will work. Note that I'm not saying which pointer as I have no idea of knowing that without seeing any real code you use. It seems the scene is invalid as you use it as if it were created on the stack.

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2006, 08:20
  2. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  3. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11:55
  4. Widget resizing problem
    By fwohlfert in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2006, 08:16
  5. Replies: 7
    Last Post: 3rd February 2006, 10:20

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
  •  
Qt is a trademark of The Qt Company.