Page 1 of 1

Problem with persistent class registration

PostPosted: Wed Apr 11, 2012 4:54 pm
by Guest
Hi,

I tried to use the example provided in the FAQ to update my database schema based on the persistent classes registered in the context.

My application crashes when this line is executed in the updateDatabaseVersion() function:

Code: Select all
qx::QxCollection<QString, qx::IxClass *> * pAllClasses = qx::QxClassX::getAllClasses();


I debugged a little and what is making it crash is the assert in the registerAllClasses() function:

Code: Select all
while (itr.hasNext())
   {
      itr.next();
      IxClass * pClass = QxClassX::getClass(itr.key());
      qAssert(pClass != NULL); Q_UNUSED(pClass); // <--- this line
   }


Apparently the classes are not registered correctly, or maybe I forgot to do something (application is working just fine though, I just have problems with introspection).

What could be the problem?

Thanks.

Re: Problem with persistent class registration

PostPosted: Wed Apr 11, 2012 8:16 pm
by talnicolas
A few more details:

I think it is due to the fact that I'm using a namespace: when calling

Code: Select all
bool QxClassX::insert(const QString & sKey, IxClass * pClass)


the key is "foo::bar::MyClass", but in the registerAllClasses() (when the getAllClasses() is called):

Code: Select all
IxClass * pClass = QxClassX::getClass(itr.key());


the key in this case is "MyClass", so the pointer is always NULL.

Re: Problem with persistent class registration

PostPosted: Thu Apr 12, 2012 10:04 am
by QxOrm admin
Hi,

I think it is due to the fact that I'm using a namespace...
...the key is "foo::bar::MyClass"...
...the key in this case is "MyClass", so the pointer is always NULL.

For classes into namespace, there is a Q&R in the FAQ : http://www.qxorm.com/qxorm_en/faq.html#faq_150
And you have an example of namespace with CPerson class into './test/qxDllSample/dll1/include/' directory.
You should try to compare your class with the example CPerson class.

Could you provide please your full source code of your 'foo::bar::MyClass' class (*.hpp and *.cpp files) ?

Re: Problem with persistent class registration

PostPosted: Thu Apr 12, 2012 1:17 pm
by talnicolas
Actually I found my solution. My problem was that I thought that this would work:

Code: Select all
using namespace foo::bar;

QX_REGISTER_COMPLEX_CLASS_NAME_CPP_SM_INSPECTOR(MyClass, foo_bar_MyClass)


but it had to be:

Code: Select all
using namespace foo::bar;

QX_REGISTER_COMPLEX_CLASS_NAME_CPP_SM_INSPECTOR(foo::bar::MyClass, foo_bar_MyClass)


So I just didn't think of adding the namespace in the macro. Thanks anyway!