[odb-users] Qt and classes derived from QObject

Boris Kolpackov boris at codesynthesis.com
Tue Feb 3 10:14:58 EST 2015

Hi Diego,

Diego Fernando <lordvampyre at gmail.com> writes:

> class Person : public QObject
> class Employee : public OQbject
> {
>   Person *person;
> }
> It's compile output:
> error: invalid cast from type 'odb::object_traits<Person>::pointer_type
> {aka QSharedPointer<Person>}' to type
> 'odb::pointer_traits<Person*>::pointer_type {aka Person*}'
>              obj_traits::object_type > (id));
> Show this line on code
>         // If a compiler error points to the line below, then
>         // it most likely means that a pointer used in a member
>         // cannot be initialized from an object pointer.
>         //
>       }
> I am using Qt and QML and exists some way to make this works without
> duplicate the code where one class is derived from QObject and another
> no.

This has nothing to do with deriving (or not) from QObject. You are
using the Qt profile which makes QSharedPointer the default object
pointer. This is probably the right choice for most situations,
including yours. So simply change:

Person *person;


QSharedPointer<Person> person;


More information about the odb-users mailing list