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?