[odb-users] Building GOF Composite Pattern ODB-1.5.0

Dan Coffey dcoffey at netharmonix.com
Wed Aug 3 12:15:40 EDT 2011


Hi Boris,

QMap<QString, QSharedPointer<Rdolls>  >

works with the odb commands.  I also tried
QMap <QString, Rdolls> contains; but this will cause odb to fail.
QMap <QString, QLazyWeakPointer<Rdolls> > contains; which works with the 
ODB preprocessor.

In the odb manual example code (pg 58) you have - std::map<insigned 
short, float> age_weight_map_;
Is it possible to have a developer defined class as the value?

Attached are the .h files, process.out which has the odb processing 
commands and results.
All of these compile in Qt Creator without error, I then run the odb 
commands and the output is process.out.
I also include the Qt files.

Thanks,

Dan

On 8/3/2011 10:20 AM, Boris Kolpackov wrote:
> Hi Dan,
>
> Dan Coffey<dcoffey at netharmonix.com>  writes:
>
>> QMap<QString, Rdolls>  contains;
> Maybe that should be:
>
>    QMap<QString, Rdolls*>
>
> Or, better yet:
>
>    QMap<QString, QSharedPointer<Rdolls>  >
>
> If that doesn't help, please send a minimal but complete header
> file that fails to compile so that I can take a look. Without
> seeing the actual C++ declarations I am just guessing.
>
> Boris
-------------- next part --------------

   ProjectExplorer.Project.ActiveTarget 0
   ProjectExplorer.Project.EditorSettings true true System false false 2
   true 1 true false true 0 2 true 1 true true true false
   ProjectExplorer.Project.Target.0 Desktop Desktop
   Qt4ProjectManager.Target.DesktopTarget 0 0 0
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe -d mysql --generate-query rdolls.h odb false %{buildDir}
   Custom Process Step ProjectExplorer.ProcessStep qmake
   QtProjectManager.QMakeBuildStep false false Make
   Qt4ProjectManager.MakeStep false 3 Build
   ProjectExplorer.BuildSteps.Build Make Qt4ProjectManager.MakeStep true
   clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Qt 4.7.3 for
   Desktop - MinGW 4.4 (Qt SDK) Debug
   Qt4ProjectManager.Qt4BuildConfiguration 2
   D:/Development/C++/TestCode/ODB/rdolls/rdolls-build-desktop 5
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe true
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe qmake QtProjectManager.QMakeBuildStep false false Make
   Qt4ProjectManager.MakeStep false 2 Build
   ProjectExplorer.BuildSteps.Build Make Qt4ProjectManager.MakeStep true
   clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Qt 4.7.3 for
   Desktop - MinGW 4.4 (Qt SDK) Release
   Qt4ProjectManager.Qt4BuildConfiguration 0
   D:/Development/C++/TestCode/ODB/rdolls/rdolls-build-desktop 5
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe true
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe qmake QtProjectManager.QMakeBuildStep false false Make
   Qt4ProjectManager.MakeStep false 2 Build
   ProjectExplorer.BuildSteps.Build Make Qt4ProjectManager.MakeStep true
   clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Qt in PATH
   Debug Qt4ProjectManager.Qt4BuildConfiguration 2
   D:/Development/C++/TestCode/ODB/rdolls/rdolls-build-desktop 8
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe true
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe qmake QtProjectManager.QMakeBuildStep false false Make
   Qt4ProjectManager.MakeStep false 2 Build
   ProjectExplorer.BuildSteps.Build Make Qt4ProjectManager.MakeStep true
   clean 1 Clean ProjectExplorer.BuildSteps.Clean 2 false Qt in PATH
   Release Qt4ProjectManager.Qt4BuildConfiguration 0
   D:/Development/C++/TestCode/ODB/rdolls/rdolls-build-desktop 8
   ProjectExplorer.ToolChain.Mingw:C:/Qt/qtcreator-2.2.1/mingw/bin/gcc.ex
   e.x86-windows-msys-pe-32bit.C:/Qt/qtcreator-2.2.1/pythongdb/gdb-i686-p
   c-mingw32.exe true 4 0 Deploy ProjectExplorer.BuildSteps.Deploy 1 No
   deployment ProjectExplorer.DefaultDeployConfiguration 1 2 false
   %{buildDir} Custom Executable
   ProjectExplorer.CustomExecutableRunConfiguration 3768 true false 1
   ProjectExplorer.Project.TargetCount 1
   ProjectExplorer.Project.Updater.EnvironmentId
   {4de63817-bbc0-4458-9419-bb6437c60248}
   ProjectExplorer.Project.Updater.FileVersion 9
-------------- next part --------------
#ifndef RDOLLS_H
#define RDOLLS_H

#include <QtCore/QString>
#include <QtCore/QMap>
//ODB includes
#include <string>
#include <odb/core.hxx>
#include <odb/qt/lazy-ptr.hxx>
#include <odb/boost/smart-ptr/pointer-traits.hxx>

#include "rdolls_global.h"
//#include "rdollsgroup.h"

//Forward Declarations
class RdollsGroup;

#pragma db object
class RDOLLSSHARED_EXPORT Rdolls {
public:
  Rdolls();

private:
  friend class odb::access;

#pragma db id auto
  unsigned long id_;

  QString last_;
  QString first_;
  unsigned short age_;

  //smart ptr to RdollsGroup
  QLazyWeakPointer<RdollsGroup> group; //This will cause odb to fail

  //QList<RdollsGroup> Below has the following error from Qt Creator build:
  // error: invalid application of 'sizeof' to incomplete type 'RdollsGroup'
  //QList<RdollsGroup> listOfGroups_;

  QList<QLazyWeakPointer<RdollsGroup> > listOfGroups;//This will cause odb to fail

  //Collection of contained Rdolls instances
  QMap<QString, Rdolls> contains; //This will cause odb to fail
  //Below all work with odb
  QMap<QString, QLazyWeakPointer<Rdolls> > contains_ptrs;
  QList<QLazyWeakPointer<Rdolls> > contains_;

  //Pointer to Rdolls instance that contain this
#pragma db inverse(contains_)
  QLazySharedPointer<Rdolls> containedIn_;
  //Rdolls containedIn;
};

#endif // RDOLLS_H
-------------- next part --------------
#ifndef RDOLLSGROUP_H
#define RDOLLSGROUP_H

#include <QtCore/QMap>
#include <string>
#include <odb/core.hxx>
#include <odb/qt/lazy-ptr.hxx>
#include <odb/boost/smart-ptr/pointer-traits.hxx>

#include "rdolls.h"
//class Rdolls;

#pragma db object
class RdollsGroup : public Rdolls
{
public:
  RdollsGroup();

private:
  friend class odb::access;

  QMap<QString, QSharedPointer<Rdolls> > contains;
};

#endif // RDOLLSGROUP_H
-------------- next part --------------
#ifndef RDOLLSLEAF_H
#define RDOLLSLEAF_H

#include <string>
#include <odb/core.hxx>
#include <odb/qt/lazy-ptr.hxx>
#include <odb/boost/smart-ptr/pointer-traits.hxx>

#include "rdolls.h"

#pragma db object
class RdollsLeaf : public Rdolls
{
public:
  RdollsLeaf();

private:
  friend class odb::access;
};

#endif // RDOLLSLEAF_H
-------------- next part --------------
+ odb -d mysql --profile qt --profile boost --generate-query --generate-schema rdolls.h -I/usr/local/include/mysql -I/usr/local/include/qt4/ -I/usr/local/include/boost -I/usr/local/include -I/usr/local/include/odb -I/d/Development/C++/TestCode/rdolls/rdolls -I/d/Development/C++/TestCode/rdolls/rdolls/rdollsgroup.h
rdolls.h:34:33: error: unable to map C++ type '::QLazyWeakPointer< ::RdollsGroup >' used in data member 'group' to a database type
rdolls.h:34:33: info: use '#pragma db type' to specify the database type
+ odb -d mysql --profile qt --profile boost --generate-query --generate-schema rdollsleaf.h -I/usr/local/include/mysql -I/usr/local/include/qt4/ -I/usr/local/include/boost -I/usr/local/include -I/usr/local/include/odb -I/d/Development/C++/TestCode/rdolls/rdolls
rdolls.h:34:33: error: unable to map C++ type '::QLazyWeakPointer< ::RdollsGroup >' used in data member 'group' to a database type
rdolls.h:34:33: info: use '#pragma db type' to specify the database type
+ odb -d mysql --profile qt --profile boost --generate-query --generate-schema rdollsgroup.h -I/usr/local/include/mysql -I/usr/local/include/qt4/ -I/usr/local/include/boost -I/usr/local/include -I/usr/local/include/odb -I/d/Development/C++/TestCode/rdolls/rdolls/rdolls.h
rdolls.h:43:25: error: unable to map C++ type '::Rdolls' used in data member 'contains' to a database type
rdolls.h:43:25: info: use '#pragma db value_type' to specify the database type
-------------- next part --------------
#-------------------------------------------------
#
# Project created by QtCreator 2011-07-28T14:19:10
#
#-------------------------------------------------

QT       += network

TARGET = rdolls
TEMPLATE = lib

DEFINES += RDOLLS_LIBRARY

SOURCES += rdolls.cpp \
    rdollsgroup.cpp \
    rdollsleaf.cpp
#rdolls-odb.cxx is generated by odb, the odb script must be run
#before rdolls-odb.cxx is compiled with rdolls.cpp
#comment out the next line before and uncomment after - dpc 8.1.11
#SOURCES += rdolls-odb.cxx

HEADERS += rdolls.h\
        rdolls_global.h \
    rdollsgroup.h \
    rdollsleaf.h

INCLUDEPATH +=  c:/MinGW/msys/1.0/local/include
INCLUDEPATH +=  c:/MinGW/msys/1.0/local/include/qt4
INCLUDEPATH +=  c:/MinGW/msys/1.0/local/include/boost

LIBS += c:/MinGW/msys/1.0/local/lib/*.a
#LIBS += c:/MinGW/msys/1.0/local/lib/odb/*
LIBS += c:/MinGW/msys/1.0/local/lib/odb/mysql/*.a
LIBS += c:/MinGW/msys/1.0/local/lib/odb/mysql/*.lib
LIBS += c:/MinGW/msys/1.0/local/lib/odb/mysql/*.dll
#Qt
LIBS += c:/MinGW/msys/1.0/local/lib/qt4/*.dll
#Not Needed libs the .a causes ld errors
#LIBS += c:/MinGW/msys/1.0/local/lib/qt4/*.a
#LIBS += c:/MinGW/msys/1.0/local/lib/qt4/*.lib



symbian {
    MMP_RULES += EXPORTUNFROZEN
    TARGET.UID3 = 0xED6D8BE0
    TARGET.CAPABILITY = 
    TARGET.EPOCALLOWDLLDATA = 1
    addFiles.sources = rdolls.dll
    addFiles.path = !:/sys/bin
    DEPLOYMENT += addFiles
}

unix:!symbian {
    maemo5 {
        target.path = /opt/usr/lib
    } else {
        target.path = /usr/lib
    }
    INSTALLS += target
}


More information about the odb-users mailing list