Error with QX_REGISTER_CPP

Forum for posting problems using QxOrm library

Error with QX_REGISTER_CPP

Postby ruddy32 » Thu Dec 09, 2010 9:11 am

Hello,
I develop an application using Linux Gentoo (amd64) platform.
I have written the following code :
My header file:
Code: Select all
#include <QxOrm.h>

namespace sdbs {
namespace ifs {
class MyClass: public BaseClass {
public:
...
};

/// data type for a MyClass pointer
typedef boost::shared_ptr<MyClass> MyClassPtr;
typedef qx::QxCollection<QString, MyClassPtr> MyClassList;

} // end namespace ifs
} // end namespace sdbs

using namespace sdbs::ifs;

QX_REGISTER_HPP(MyClass, qx::trait::no_base_class_defined, 1)

My source file:
Code: Select all
#include "entity/MyClass.hpp"

QX_REGISTER_CPP(MyClass)

namespace qx {
template<>
void register_class(QxClass<MyClass> & t) {
   MyClass::registerOrmClass(t);
}
}
...

Error log:
Code: Select all
../src/main/cpp/entity/MyClass.cpp:14: error: expected identifier before string constant
../src/main/cpp/entity/MyClass.cpp:14: error: expected ‘,’ or ‘...’ before string constant
../src/main/cpp/entity/MyClass.cpp:14: error: expected constructor, destructor, or type conversion before ‘qx’

Is it possible to define object classes in namespace and use it with QxOrm? Is it the right way to do it?
Thanks
ruddy32
 

Re: Error with QX_REGISTER_CPP

Postby QxOrm admin » Thu Dec 09, 2010 11:29 am

Hi,

1- Don't include " #include <QxOrm.h> " in your header file :
I strongly recommend to use precompiled header to reduce compilation times (gcc supports precompiled header very well).

2- Can you post the code of your macro "QX_REGISTER_CPP" and "QX_REGISTER_HPP" please ?
You must create your own macro to know if you are building your lib or not (like dll process on windows).
I recommend to create a file "export.h" : you can find sample in the directories : "QxOrm\test\dll1\include\", "QxOrm\test\dll2\include\" and "D:\Dvlp\_Perso\QxOrm\test\qxBlog\include\".
You can include this "export.h" file in your precompiled header...

3- Yes you can create classes under namespace : you can find a sample with class "CPerson" in the directory : "QxOrm\test\dll1\".
You have to use a macro "...COMPLEX_CLASS_NAME..." in this case.
Here the code of "export.h" file in the "dll1" sample (see "QX_REGISTER_COMPLEX_CLASS_NAME_HPP_QX_DLL1" and "QX_REGISTER_COMPLEX_CLASS_NAME_CPP_QX_DLL1" macro) :

Code: Select all
#ifndef _QX_DLL1_EXPORT_H_
#define _QX_DLL1_EXPORT_H_

#ifdef _MSC_VER
#pragma once
#endif

#ifdef _QX_BUILDING_DLL1
#define QX_DLL1_EXPORT QX_DLL_EXPORT_HELPER
#else // _QX_BUILDING_DLL1
#define QX_DLL1_EXPORT QX_DLL_IMPORT_HELPER
#endif // _QX_BUILDING_DLL1

#ifdef _QX_BUILDING_DLL1
#define QX_REGISTER_HPP_QX_DLL1 QX_REGISTER_HPP_EXPORT_DLL
#define QX_REGISTER_CPP_QX_DLL1 QX_REGISTER_CPP_EXPORT_DLL
#define QX_REGISTER_COMPLEX_CLASS_NAME_HPP_QX_DLL1 QX_REGISTER_COMPLEX_CLASS_NAME_HPP_EXPORT_DLL
#define QX_REGISTER_COMPLEX_CLASS_NAME_CPP_QX_DLL1 QX_REGISTER_COMPLEX_CLASS_NAME_CPP_EXPORT_DLL
#else // _QX_BUILDING_DLL1
#define QX_REGISTER_HPP_QX_DLL1 QX_REGISTER_HPP_IMPORT_DLL
#define QX_REGISTER_CPP_QX_DLL1 QX_REGISTER_CPP_IMPORT_DLL
#define QX_REGISTER_COMPLEX_CLASS_NAME_HPP_QX_DLL1 QX_REGISTER_COMPLEX_CLASS_NAME_HPP_IMPORT_DLL
#define QX_REGISTER_COMPLEX_CLASS_NAME_CPP_QX_DLL1 QX_REGISTER_COMPLEX_CLASS_NAME_CPP_IMPORT_DLL
#endif // _QX_BUILDING_DLL1

#endif // _QX_DLL1_EXPORT_H_
QxOrm admin
 

Re: Error with QX_REGISTER_CPP

Postby ruddy32 » Thu Dec 09, 2010 2:52 pm

I'm using QxOrm in an application, not a library. And I'm using default macro from QxOrm 1.1.3.
Code: Select all
#define QX_REGISTER_HPP(className, baseClass, version) \
QX_REGISTER_COMPLEX_CLASS_NAME_HPP(className, baseClass, version, className)

Code: Select all
#define QX_REGISTER_CPP(className) \
QX_REGISTER_COMPLEX_CLASS_NAME_CPP(className, className)
ruddy32
 

Re: Error with QX_REGISTER_CPP

Postby ruddy32 » Thu Dec 09, 2010 3:01 pm

I have switch to QX_REGISTER_COMPLEX_CLASS_NAME_HPP and QX_REGISTER_COMPLEX_CLASS_NAME_CPP with the same build error on QX_REGISTER_COMPLEX_CLASS_NAME_CPP.
Code: Select all
...
class IFSEntity: public QObject {
public:
...
};
...

Code: Select all
...
class MyClass: public IFSEntity {
   Q_OBJECT
   QX_REGISTER_FRIEND_CLASS(sdbs::ifs::MyClass)
   friend class boost::serialization::access;
   friend class ServiceCLI;

public:
...
};
...
} // end namespace ifs
} // end namespace sdbs

QX_REGISTER_COMPLEX_CLASS_NAME_HPP(sdbs::ifs::MyClass, QObject, 1, sdbs_ifs_MyClass)
...

Code: Select all
...
QX_REGISTER_COMPLEX_CLASS_NAME_CPP(sdbs::ifs::MyClass, sdbs_ifs_MyClass)
namespace qx {
template<>
void register_class(QxClass<sdbs::ifs::MyClass> & t) {
...
};

Is it necessary to provide my class in qx namespace ?
ruddy32
 

Re: Error with QX_REGISTER_CPP

Postby QxOrm admin » Thu Dec 09, 2010 3:12 pm

No you don't have to set your class in qx namespace.

The problem is that you don't use the good macro.

This is the same thing for an application or a library :
- You must not use directly macro of QxOrm library
- You must create your own "export.h" file like samples provided in directory : "QxOrm/test/..."

In your case, if you just have an application without shared or static libraries, and if you don't want to create the file "export.h", you have to use the followings macro :
- QX_REGISTER_HPP_EXPORT_DLL / QX_REGISTER_CPP_EXPORT_DLL
- QX_REGISTER_COMPLEX_CLASS_NAME_HPP_EXPORT_DLL / QX_REGISTER_COMPLEX_CLASS_NAME_CPP_EXPORT_DLL (if you define your classes under namespace)
QxOrm admin
 

Re: Error with QX_REGISTER_CPP

Postby QxOrm admin » Thu Dec 09, 2010 3:15 pm

Another thing, this is not necessary with QxOrm to write in your class :
Code: Select all
friend class boost::serialization::access;
QxOrm admin
 

Re: Error with QX_REGISTER_CPP

Postby ruddy32 » Thu Dec 09, 2010 3:55 pm

I'm using gcc 4.4, boost 1.41, qt-sql 4.6.3.

The first error handle BOOST_CLASS_EXPORT_GUID, and the second handle QX_REGISTER_FACTORY_COMPLEX_CLASS_NAME_CPP macro used by QX_REGISTER_COMPLEX_CLASS_NAME_CPP_EXPORT_DLL.

boost macro available in my environment
Code: Select all
#define BOOST_CLASS_EXPORT_IMPLEMENT(T)                      \
    namespace boost {                                        \
    namespace archive {                                      \
    namespace detail {                                       \
    namespace {                                              \
    template<>                                               \
    struct init_guid< T > {                                  \
        static guid_initializer< T > const & g;              \
    };                                                       \
    guid_initializer< T > const & init_guid< T >::g =        \
        ::boost::serialization::singleton<                   \
            guid_initializer< T >                            \
        >::get_mutable_instance().export_guid();             \
    }}}}                                                     \
/**/

#define BOOST_CLASS_EXPORT_KEY2(T, K)          \
namespace boost {                              \
namespace serialization {                      \
template<>                                     \
struct guid_defined<T> : boost::mpl::true_ {}; \
template<>                                     \
inline const char * guid<T>(){                 \
    return K;                                  \
}                                              \
} /* serialization */                          \
} /* boost */                                  \
/**/

#define BOOST_CLASS_EXPORT_KEY(T)                                      \
    BOOST_CLASS_EXPORT_KEY2(T, BOOST_PP_STRINGIZE(T))                                                                  \
/**/

#define BOOST_CLASS_EXPORT_GUID(T, K)                                  \
BOOST_CLASS_EXPORT_KEY2(T, K)                                          \
BOOST_CLASS_EXPORT_IMPLEMENT(T)                                        \
/**/
ruddy32
 

Re: Error with QX_REGISTER_CPP

Postby QxOrm admin » Thu Dec 09, 2010 4:07 pm

Do you compile and execute without problem all tests cases in "QxOrm/test/" directory ?
I think this is the first thing to do : dll1, dll2, exe and qxBlog must build without error before using QxOrm, and must execute without error or assert.
If you have a problem with tests cases, perhaps this is due to your install.

If all tests cases are ok, then I recommend to compare your application and qxBlog application...
QxOrm admin
 

Re: Error with QX_REGISTER_CPP

Postby ruddy32 » Thu Dec 09, 2010 9:31 pm

I solve it by adding this line "#include <boost/serialization/export.hpp>" just after "#include <QxOrm.h>". I do not use "#include <QxMemLeaks.h>". :|
ruddy32
 

Re: Error with QX_REGISTER_CPP

Postby QxOrm admin » Fri Dec 10, 2010 8:11 am

Yes this is true !
There is some problems if you insert "#include <boost/serialization/export.hpp>" in the precompiled header (at least with Visual Studio compiler).
This is why QxOrm library uses this trick : "#include <boost/serialization/export.hpp>" inside "#include <QxMemLeaks.h>".

PS: perhaps this is resolved by boost serialization team in the last version (???).
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 9 guests