[odb-users] Compilation error when calling QLazyWeakPointer<T>::load()

Gilles Bene gilles.benepougoue at gmail.com
Wed Feb 22 13:45:55 EST 2017


Hi,
Thanks for your prompt reply.
Actually I want load() to return QSharedPointer<Sortie> instead of Sortie*.

I've' used the --default-pointer option to specify the default pointer for
the
whole file by suppliying it as ODB Compiler Command Line option in my make
file.
And I can see that the option is actually supplied to odb at compile time
as I can see the output of make calling odb.

odb -x -fPIC -x --std=c++11 --database pgsql --sql-name-case lower
--profile qt --default-pointer QSharedPointer --hxx-prologue-file
../pointer-par-defaut.hxx --generate-query --generate-session
-I/usr/include/x86_64-linux-gnu/qt5 Sortie.hxx

the file  pointer-par-defaut.hxx contains the line:
#include <QtCore/QSharedPointer>

But I still have the same error message.
I've check the file Sortie-odb.hxx wether it actually include the
definition
of the default pointer. I notice that it actually has the include #include
<QtCore/QSharedPointer>
Here is a part of the file Sortie-odb.hxx:

// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//

#ifndef SORTIE_ODB_HXX
#define SORTIE_ODB_HXX

// Begin prologue.
//
#include <odb/qt/version.hxx>
#if ODB_QT_VERSION != 2040000 // 2.4.0
#  error ODB and C++ compilers see different libodb-qt interface versions
#endif
#include <odb/qt/basic/pgsql/qstring-traits.hxx>
#include <odb/qt/basic/pgsql/qbyte-array-traits.hxx>
#include <odb/qt/basic/pgsql/quuid-traits.hxx>
#include <odb/qt/containers/qhash-traits.hxx>
#include <odb/qt/containers/qlist-traits.hxx>
#include <odb/qt/containers/qlinked-list-traits.hxx>
#include <odb/qt/containers/qmap-traits.hxx>
#include <odb/qt/containers/qset-traits.hxx>
#include <odb/qt/containers/qvector-traits.hxx>
#include <odb/qt/date-time/pgsql/qdate-traits.hxx>
#include <odb/qt/date-time/pgsql/qtime-traits.hxx>
#include <odb/qt/date-time/pgsql/qdate-time-traits.hxx>
#include <QtCore/QSharedPointer>
#include <odb/qt/smart-ptr/pointer-traits.hxx>
#include <odb/qt/smart-ptr/wrapper-traits.hxx>
#include <QtCore/QSharedPointer>


//
// End prologue.

#include <odb/version.hxx>

#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif

#include <odb/pre.hxx>

#include "Sortie.hxx"

#include "../DocsRelances/Relancable-odb.hxx"
#include "Relance-odb.hxx"
#include "../Personnels/Personnel-odb.hxx"
#include "Emballage-odb.hxx"
#include "Fournisseur-odb.hxx"
#include "HistPrix-odb.hxx"
#include "PrixFourn-odb.hxx"
#include "../Produits/Produit-odb.hxx"
#include "Tonnage-odb.hxx"
#include "DetailsSortie-odb.hxx"
#include "Facture-odb.hxx"
#include "Reglement-odb.hxx"

#include <memory>
#include <cstddef>
#include <string>

#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/session.hxx>
#include <odb/cache-traits.hxx>
#include <odb/polymorphic-info.hxx>
#include <odb/result.hxx>
#include <odb/polymorphic-object-result.hxx>

#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>

namespace odb
{
  // Sortie
  //
  template <>
  struct class_traits< ::Sortie >
  {
    static const class_kind kind = class_object;
  };

  template <>
  class access::object_traits< ::Sortie >
  {
    public:
    typedef ::Sortie object_type;
    typedef ::QSharedPointer< ::Sortie > pointer_type;
    typedef odb::pointer_traits<pointer_type> pointer_traits;

    static const bool polymorphic = true;

    typedef ::Sortie root_type;
    typedef ::std::string discriminator_type;
    typedef polymorphic_map<object_type> map_type;
    typedef polymorphic_concrete_info<object_type> info_type;

// ......

I tought the line
typedef ::QSharedPointer< ::Sortie > pointer_type;
Was the specifying the default pointer for all instances of Sortie.
I looked for anything like odb::object_traits<Sortie>::pointer_type
as appearing in the error message but couldn't fine.
May be am getting something wrong.
Please need your advice. Sorry for my lengthy message.

On 21 February 2017 at 17:49, Boris Kolpackov <boris at codesynthesis.com>
wrote:

> Hi Gilles,
>
> Gilles Bene <gilles.benepougoue at gmail.com> writes:
>
> > /usr/include/odb/qt/smart-ptr/lazy-ptr.ixx:473:7: error: no match for
> > 'operator=' (operand types are 'QSharedPointer<Sortie>' and
> > 'odb::object_traits<Sortie>::pointer_type {aka Sortie*}')
> >      r = i_.template load<T> (false); // Keep id.
> >        ^
>
> Well, the compiler tells you exactly what the problem is: load() returns
> Sortie* and left-hand-side is QSharedPointer<Sortie>. And that assignment
> is not valid. Which one would be valid? For example, QSharedPointer<Sortie>
> to QSharedPointer<Sortie>. Why is load() returning Sortie* instead of
> QSharedPointer<Sortie>? Because you haven't told ODB that your object
> pointers should be something other than raw pointers (see Section 3.3,
> "Object and View Pointers" in the manual).
>
> Boris
>
>
>


-- 
Gilles BENE POUGOUE


More information about the odb-users mailing list