Qt Serializion custom class

what is wrong in my code !!!! i got the following error message: unresolved external symbol. any suggestions .. and what is the proper whay to inhert from QObject whit out getting you trying to access private member .

namespace BioQt {
     class Location : public QObject
    {
        Q_OBJECT
    public:
        explicit Location(QObject *parent );

    };
    QDataStream &operator<<(QDataStream &out, const Location &obj);
    QDataStream &operator>>(QDataStream &in, Location &obj);

    }


    Q_DECLARE_TYPEINFO(BioQt::Location, Q_PRIMITIVE_TYPE);

#endif

and this is my cpp file

namespace BioQt {

Location::Location(QObject *parent)
    : QObject(parent)
{

}



QDataStream &operator<<(QDataStream &ds, const Location &obj) {
    for(int i=0; i<obj.metaObject()->propertyCount(); ++i) {
        if(obj.metaObject()->property(i).isStored(&obj)) {
            ds << obj.metaObject()->property(i).read(&obj);

        }
    }
    return ds;
}
QDataStream &operator>>(QDataStream &ds, Location &obj) {
    QVariant var;
    for(int i=0; i<obj.metaObject()->propertyCount(); ++i) {
        if(obj.metaObject()->property(i).isStored(&obj)) {
            ds >> var;
            obj.metaObject()->property(i).write(&obj, var);
        }
    }
    return ds;
}

} // namespace BioQt

Answers


I managed to compile with Qt 5.4.0 vs2010 x86 with no errors. Back in days with Qt 4.7, i remember sthg similar, moving the body to the header file and using inline worked for me, as i remember.


Need Your Help

showing MongoDB document value to EJS in a loop

node.js mongodb loops view ejs

I'm working on a node project. And node is very new to me so sorry if I ask a lot of stupid questions.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.