-1

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
cmannett85
  • 21,725
  • 8
  • 76
  • 119
alrawab
  • 217
  • 3
  • 8
  • 1
    There are several things that appear wrong with this, but start by posting the exact error message. – cmannett85 Jan 26 '15 at 15:25
  • mention one of the several wrongs :) where even when i pass o or null to parent i got the same error ... – alrawab Jan 26 '15 at 15:27
  • Your stream declarations use a double ampersand, which is a universal reference in C++11 and doesn't match the definitions. You declare the class as a primitive type, which it plainly is not. You define the stream operator inside the `BioQt` namespace instead of fully qualifying the argument type. Now post the exact error message. – cmannett85 Jan 26 '15 at 15:34
  • this is the error message :Location.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BioQt::Location::metaObject(void)const " (?metaObject@Location@BioQt@@UBEPBUQMetaObject@@XZ) – alrawab Jan 26 '15 at 15:36
  • declarations use a double ampersand : i correct the post there is no double ampersand in my code copy past issues :) – alrawab Jan 26 '15 at 15:47
  • possible duplicate of [Unresolved external symbol "public: virtual struct QMetaObject const \* \_\_thiscall Parent](http://stackoverflow.com/questions/14170770/unresolved-external-symbol-public-virtual-struct-qmetaobject-const-thiscal) – cmannett85 Jan 26 '15 at 15:48
  • the proplem in Q_OBJECT but how to solve that – alrawab Jan 26 '15 at 15:55

1 Answers1

0

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.

cobalt
  • 86
  • 4