Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:11:36+00:00 2026-06-15T14:11:36+00:00

I am writing an image viewer with Qt based on the QGraphicsScene feature of

  • 0

I am writing an image viewer with Qt based on the QGraphicsScene feature of Qt. I am creating model of each image in a class called ImageModel and manage the display of the image in a class called ImageView. The ImageView class is as follows (just the part that is interesting):

class ImageView
{
public:
    ImageView(QWidget *parent);

    QGraphicsView * getView() {return view; }

private:

    //qgraphics scene elements
    QGraphicsScene *scene;
    QGraphicsView *view;
    QGraphicsPixmapItem *curItem;


};

The constructor for the class is as follows:

ImageView::ImageView(QWidget *parent)
{

    //create scene and view with parent the main window
    //such that the memory management is done by qt
    scene = new QGraphicsScene(parent);
    view = new QGraphicsView(parent);

    view->setScene(scene);
}

Also I have pointer to an ImageView in my derivation of the QMainWindow.

My question is: should I let Qt do the memory management by seting my main window as parent of the view and the scene or should I take care of the memory management myself (leave the view and the scene without parents and delete them in the class destructors)? What is a good strategy in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:11:37+00:00Added an answer on June 15, 2026 at 2:11 pm

    If you want the view to be nested inside the main window, then you will have to make it a child.

    For your general question, this really comes down to your desired object lifetimes and ownership semantics. If you don’t want to the view/scene to outlive the main window then yes they should be children. You still have the option to delete them through other means at an earlier time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an image viewer as a custom Qt widget (see: https://github.com/dov/Qviv ) and
I'm writing an image class for a game I'm working on and some images
I am writing an image viewer with Qt. I am trying to do the
I'm writing an image binarization algorithm which simply converts each pixel's luminance value (grayscale
I'm writing an image viewer, and I'd like some behavior from Qt: imagine the
I am writing a straightforward image viewer for displaying images on a couple of
I'm writing a simple image upload function with php + image magick using amazon
I am writing a program to do some image processing. I am working with
I'm writing a program about image-processing. I need to store an int square matrix
I am writing a sort of image processing program that allows the user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.