Constantin
Constantin

Reputation: 17768

Using Boost Serialize With A Qt Plugin

All, I am attempting to serialize a Qt Plugin infrastructure using boost. A quick description of my plugin infrastructure -- All plugins are factories, let's call them ObjectFactories. Each plugin .so/.dll is constructed from two classes

My problem is that when I serialize an object from my plugin (in a console test program), I get an exception of derived class not registered or exported

objectfactory.cpp/.h:

class ObjectFactory : public QObject, public [PluginInterface]
{
    //most important method
    BaseObject * createBaseObject();
}

derivedobject.h:

#include "base_object.h"

#include <boost/archive/basic_text_iarchive.hpp>
#include <boost/archive/basic_text_oarchive.hpp>

namespace MyNamespace
{

class DerivedObject : public BaseObject
{
public:
    DerivedObject();

    ~DerivedObject();

private:
    BaseObjectData<double> m_data;

    template<class Archive>
    void serialize(Archive &ar, const unsigned int version)
    {
        ar & boost::serialization::base_object<BaseObject>(*this);
        ar & m_data.data(); // T & BaseObjectData::data() - returns reference
    }
};

}

BOOST_CLASS_EXPORT_KEY(MyNamespace::DerivedObject) //Register our class for serialization/deserialization

At the bottom of the derivedobject.cpp:

 BOOST_CLASS_EXPORT_IMPLEMENT(Mynamespace::DerivedObject)

However, I am still getting

what(): unregistered class - derived class not registered or exported

If anyone could offer any advice it would be appreciated. I would be glad to add any more sources that I need. An important note, the two classes (ObjectFactory and DerivedObject) exist within the same *.so I don't know if that matters.

Upvotes: 1

Views: 285

Answers (1)

Constantin
Constantin

Reputation: 17768

Okay, got it...

In my base and derived headers:

#include <boost/archive/basic_text_iarchive.hpp>
#include <boost/archive/basic_text_oarchive.hpp>

while in my test program:

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

I had to make those two match up.

Upvotes: 1

Related Questions