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

  • Home
  • SEARCH
  • 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 8987965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:58+00:00 2026-06-15T21:54:58+00:00

I noticed that when substituting raw pointers with shared_ptr in QT, my code does

  • 0

I noticed that when substituting raw pointers with shared_ptr in QT, my code does not work anymore.
For example, if instead of

 QTreeWidgetItem* vItem(new QTreeWidgetItem(ItemTitle));

I use

 std::shared_ptr<QTreeWidgetItem> vItem(new QTreeWidgetItem(ItemTitle));

then, either the program crashes or nothing is done (even if I use the .get() function to get the
raw pointer from the shared one later in my code). Does anybody knows what could be the cause?

  • 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-15T21:54:59+00:00Added an answer on June 15, 2026 at 9:54 pm

    Using shared pointer with Qt model items causes an ownership conflict: QTreeWidget takes ownership of any QTreeWidgetItem you pass to it. std::shared_ptr also owns its item. Both assume they can delete the item themselves and that nobody else will delete it behind their back.

    In such situations, where Qt takes ownership of the pointers (other example: parent QObject taking ownership of its children), one cannot use std::shared_ptr/QSharedPointer at the same time. std::shared_ptr only works well when using std::shared_ptr and std::weak_ptr exclusively to hold pointers to that particular object.

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

Sidebar

Related Questions

I noticed that IE 9 does not support application cache. How can I use
I noticed that itertools does not (it seems to me) have a function capable
I noticed that, for the most part, Django does not enforce default values on
I noticed that DateChooser has the method setFirstDayOfWeek(int) , but since DateChooser does not
I noticed that the <td align=center> code works differently on the MediaWiki.org page and
I noticed that static assertions in class templates are not triggered when instantiations are
I noticed that every tutorial on how to do JavaScript inheritance does this: SubClass.prototype
Template specialization does not take into account inheritance hierarchy. For example, if I specialize
Noticed that if I want to read some data and if I do not
I noticed that WPF application startup is sometimes pretty slow. Does anybody know if

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.