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 912933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:28:06+00:00 2026-05-15T17:28:06+00:00

I am writing Qt-based app with Blender-like functionality. It consists of a ‘framework’ which

  • 0

I am writing Qt-based app with Blender-like functionality.

It consists of a ‘framework’ which is GUI + plugin system and plugins. Plugins are Qt dlls with objects (e.g. a Sphere, a Box, etc.) that can be basically created and displayed. All those objects, once created, are stored in the framework in some kind of a container structure which holds shared_ptr’s to them (so actually the container is pretty much like vector<shared_ptr<INode>>)

What I want is to use shared_from_this() function inside one of plugins.
E.g. Here’s a sample plugin (code changed for clarity):

class Q_DECL_IMPORT SphereNode: public INode, public Sphere

Where INode is:

class INode: public QObject, public boost::enable_shared_from_this<INode>

,a base class for everything stored in the container. So the problem is that this function:

void SphereNode::update()
{
 foo(shared_from_this());
}

throws a boost::bad_weak_ptr exception.

A couple of notes how this SphereNode is created (a Factory class)

boost::shared_ptr<INode> NodeFactory::createNode(const QString& type, QString tag)
{
...
QPluginLoader loader(filesPlugin_[i]);
boost::shared_ptr<QObject> plugin(loader.instance());
boost::shared_ptr<INode> iNodePlugin = boost::shared_dynamic_cast<INode>(plugin);
return iNodePlugin;
}

Any ideas?

  • 1 1 Answer
  • 1 View
  • 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-05-15T17:28:07+00:00Added an answer on May 15, 2026 at 5:28 pm

    Perhaps it is this line:

    boost::shared_ptr<INode> iNodePlugin = boost::shared_dynamic_cast<INode>(plugin);
    

    Which should be replaced by:

    boost::shared_ptr<INode> iNodePlugin = dynamic_cast<INode*>(loader.instance())->shared_from_this();
    

    Maybe it has something to do with:

    boost::shared_ptr<QObject> plugin(loader.instance());
    

    Here plugin takes ownership of the returned instance. However, the Qt documentation states that the instance will be automatically freed by the QPluginLoader upon destruction.

    However, this would rather cause a segfault (undefined behavior) than a regular boost::bad_weak_ptr exception.

    If you want to prevent this, you can specify a null_deleter that will do nothing when the reference counter reachs 0.


    Are you calling shared_from_this() from either a constructor or a destructor (directly or indirectly) ?

    If so, there is your problem.

    When you’re in the constructor, the object is not fully created yet, so having a shared_ptr to it is invalid.

    To avoid this issue, you can get your shared_ptr to the object in a factory method (that you already have anyway), when the object was succesfully constructed.

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

Sidebar

Related Questions

I'm writing a little tile-based game, for which I'd like to support light sources.
I am writing an App based on UITabBarController which has more than 10 viewControllers
I am writing an opengl based iphone app and would like to allow a
I'm writing a Navigation-Based iPhone app, and I'd like to have a UIToolBar docked
I am writing a small Sinatra-based app and would like each view to be
I am writing an iframe based facebook app. Now I want to use the
I am currently writing a simple, timer-based mini app in C# that performs an
Several frameworks for writing web-based desktop-like applications have recently appeared. E.g. SproutCore and Cappuccino
Is there any GUI-based tools to assist you with writing and maintaining the configuration
I'm writing a view based app, but I'm a bit confused about loading my

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.