Problems with registering a class to QxORM

Forum for posting problems using QxOrm library

Problems with registering a class to QxORM

Postby zbenjamin » Mon Dec 12, 2011 11:29 am

I have the following Code:

my export.h

Code: Select all
#ifndef ESF_EASYORDR_EXPORT_H
#define ESF_EASYORDR_EXPORT_H

#include <QxOrm.h>

#ifdef BUILDING_EASYORDR
#define ESF_EASYORDR_EXPORT QX_DLL_EXPORT_HELPER
#else // BUILDING_EASYORDR
#define ESF_EASYORDR_EXPORT QX_DLL_IMPORT_HELPER
#endif // BUILDING_EASYORDR

#ifdef BUILDING_EASYORDR
#define QX_REGISTER_HPP_ESF_EASYORDR QX_REGISTER_HPP_EXPORT_DLL
#define QX_REGISTER_CPP_ESF_EASYORDR QX_REGISTER_CPP_EXPORT_DLL
#else // BUILDING_EASYORDR
#define QX_REGISTER_HPP_ESF_EASYORDR QX_REGISTER_HPP_IMPORT_DLL
#define QX_REGISTER_CPP_ESF_EASYORDR QX_REGISTER_CPP_IMPORT_DLL
#endif // BUILDING_EASYORDR


#endif // ESF_EASYORDR_EXPORT_H


Code: Select all
#ifndef MANDATOR_H
#define MANDATOR_H

#include <core/precompiled.h>

class ESF_EASYORDR_EXPORT Mandator
{
    public:
        Mandator();

        static void registerOrm (qx::QxClass<Mandator> & t);
    public:
        long m_id;
        QString m_name;
};

QX_REGISTER_HPP_ESF_EASYORDR(Mandator, qx::trait::no_base_class_defined, 1)

typedef QSharedPointer<Mandator> Mandator_ptr;
typedef qx::QxCollection<QString, Mandator_ptr> list_Mandator;

#endif // MANDATOR_H


Code: Select all
#include <core/mandator.h>

QX_REGISTER_CPP_ESF_EASYORDR(Mandator)

namespace qx {
template <> void register_class(QxClass<Mandator> & t)
{
    Mandator::registerOrm(t);
}}


Mandator::Mandator()
{
}

void Mandator::registerOrm(qx::QxClass<Mandator> &t)
{
    t.id(& Mandator::m_id, "id");
    t.data(& Mandator::m_name, "fldName");
}


And i always get this error:
Code: Select all
src/core/mandator.cpp:3:1: error: expected identifier before string constant
src/core/mandator.cpp:3:1: error: expected ‘,’ or ‘...’ before string constant
src/core/mandator.cpp:3:1: error: expected constructor, destructor, or type conversion before ‘qx’


Any idea whats the cause for that error?

regards zbenjamin
zbenjamin
 
Posts: 5
Joined: Wed Dec 07, 2011 10:34 pm

Re: Problems with registering a class to QxORM

Postby QxOrm admin » Mon Dec 12, 2011 1:11 pm

Hi,

At least 2 things with your code :
- don't include your precompiled file in the HPP file (a precompiled header must included into each CPP file)
- you must include <QxMemLeak.h> file in your CPP file (you can try to put it in your precompiled header but on some compilers, it's not working)

For more informations, you can read the tutorial qxBlog (part 5) :
http://www.qxorm.com/qxorm_en/tutorial.html#tuto_5
QxOrm admin
 

Re: Problems with registering a class to QxORM

Postby zbenjamin » Mon Dec 12, 2011 1:36 pm

QxOrm admin wrote:Hi,

At least 2 things with your code :
- don't include your precompiled file in the HPP file (a precompiled header must included into each CPP file)

Hm I included it in the Header file because creator otherwise would bitch about missing types and macros.

QxOrm admin wrote: - you must include <QxMemLeak.h> file in your CPP file (you can try to put it in your precompiled header but on some compilers, it's not working)

Oh i saw some statement that one does not need to use QxMemLeak and that its disabled by default so i thought i don't have to include it.
Anyway that fixed the three errors but came up with new ones:

Code: Select all
src/core/mandator.cpp:5:1:   instantiated from here
../QxOrm/include/QxRegister/QxClass.h:151:225: error: cannot dynamic_cast ‘pOwner’ (of type ‘class Mandator*’) to type ‘qx::QxClass<Mandator>::type_base_class* {aka class qx::trait::no_base_class_defined*}’ (source type is not polymorphic)
../QxOrm/include/QxRegister/QxClass.h: In member function ‘qx_bool qx::QxClass<T>::invokeHelper(const QString&, T*, const type_any_params&, boost::any*) [with T = Mandator, qx_bool = qx::QxBool, qx::QxClass<T>::type_any_params = std::vector<boost::any>]’:
src/core/mandator.cpp:5:1:   instantiated from here
../QxOrm/include/QxRegister/QxClass.h:154:225: error: cannot dynamic_cast ‘pOwner’ (of type ‘class Mandator*’) to type ‘qx::QxClass<Mandator>::type_base_class* {aka class qx::trait::no_base_class_defined*}’ (source type is not polymorphic)
zbenjamin
 
Posts: 5
Joined: Wed Dec 07, 2011 10:34 pm

Re: Problems with registering a class to QxORM

Postby QxOrm admin » Mon Dec 12, 2011 6:02 pm

Hm I included it in the Header file because creator otherwise would bitch about missing types and macros.

It's very important to use precompiled header correctly.
You have to write something like this in your PRO file : PRECOMPILED_HEADER = ./include/precompiled.h
Without the precompiled file, compilation times will be too long to use QxOrm library.

Do you have tested all examples in the directory "./test/" of QxOrm package ?
This is a good start before creating your first project using QxOrm library...

Anyway that fixed the three errors but came up with new ones

Your Mandator class must be a polymorphic type : if you don't have a virtual method into your class (this is your case), just add a virtual destructor, like this :
virtual ~Mandator() { ; }
QxOrm admin
 

Re: Problems with registering a class to QxORM

Postby QxOrm admin » Mon Dec 12, 2011 6:56 pm

2 other things about your code :
- you have to include "#include <QxOrm.h>" in your precompiled header file, not in the export.h file.
- why do you create the method "static void registerOrm (qx::QxClass<Mandator> & t);" ?
You don't have to create this method : indeed, void qx::register_class<T>function will be called automatically by QxOrm engine, and you don't have to create another caller !
QxOrm admin
 

Re: Problems with registering a class to QxORM

Postby zbenjamin » Tue Dec 13, 2011 7:57 am

QxOrm admin wrote: - why do you create the method "static void registerOrm (qx::QxClass<Mandator> & t);" ?
You don't have to create this method : indeed, void qx::register_class<T>function will be called automatically by QxOrm engine, and you don't have to create another caller !


Because i don't want to make my class members public, the static function makes it possible for me to acccess the private members
zbenjamin
 
Posts: 5
Joined: Wed Dec 07, 2011 10:34 pm

Re: Problems with registering a class to QxORM

Postby QxOrm admin » Tue Dec 13, 2011 8:23 am

Because i don't want to make my class members public, the static function makes it possible for me to acccess the private members

Just use the macro QX_REGISTER_FRIEND_CLASS(MyClass) if you want private or protected members (for example, see the file './test/qxDllSample/dll1/include/CPerson.h' into QxOrm package).
And then you can remove your static method, it is not necessary.
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 3 guests