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

Dan Coffey dcoffey at netharmonix.com
Wed Aug 3 14:02:12 EDT 2011


Hi Boris,

By changing the attribute name in the RdollsGroup class from */contains 
/*to */group /*that last error went away.
QMap<QString, QSharedPointer<Rdolls> > *contains*;
to
QMap<QString, QSharedPointer<Rdolls> > *group*;

The base class (Rdolls) has an attribute:
QList<QLazyWeakPointer<Rdolls>>*contains_*;

With that error gone, now I'm getting this compiler error in Qt Creator:
In rdollsgroup-odb.cxx
//Ifacompilererrorpointstothelinebelow,then
//itmostlikelymeansthatapointerusedinamember
//cannotbeinitializedfromanobjectpointer.

         v  =  ptr_traits::pointer_type  (

           db.load<  ptr_traits::element_type  >  (id));

So I changed theabove QMap from
QMap<QString, QSharedPointer<Rdolls> >
to
QMap<QString, QLazyWeakPointer<Rdolls> >

and that compiled with no errors.
Next I'm going to create the database.hxx and driver.cxx and test it out.

Thanks,

Dan



On 8/3/2011 1:12 PM, Dan Coffey wrote:
> Hi Boris,
>
> I've commented out all of the lines that cause odb processing errors 
> (attached src on last email)
> I then compiled the files (Rdolls ...) using Qt Creator
> Then I ran the odb command for each .cpp file without errors and the 
> *-odb.[ch]xx and *.ixx files were created without errors.
> The Qt .pro file was modified to include all of the created 
> *-odb.[ch]xx files.
> When I do a rebuild all in Qt I get the following errors from the 
> rdollsgroup-odb.hxx file
>
> /D:\Development\C++\TestCode\ODB\rdolls\rdolls-build-desktop\..\rdolls\rdollsgroup-odb.hxx:118: 
> error: redefinition of 'struct 
> odb::access::object_traits<RdollsGroup>::contains_traits'
>
> D:\Development\C++\TestCode\ODB\rdolls\rdolls-build-desktop\..\rdolls\rdollsgroup-odb.hxx:107: 
> error: previous definition of 'struct 
> odb::access::object_traits<RdollsGroup>::contains_traits'/
>
> Thanks,
>
> Dan
>
> Env:
> XP SP3
> minGW
> Qt 4.7
> g++ 4.5.2
>
> On 8/3/2011 12:15 PM, Dan Coffey wrote:
>> 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 --------------
#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"

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

private:
  friend class odb::access;

  QMap<QString, QLazyWeakPointer<Rdolls> > group;
  //QMap<QString, QSharedPointer<Rdolls> > group;
};

#endif // RDOLLSGROUP_H
-------------- 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

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


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

#  *-odb.hxx is generated by odb, the odb script must be run
#before *-odb.hxx is compiled with rdolls.cpp
#comment out the next lines before and uncomment after - dpc 8.1.11
HEADERS += rdolls-odb.hxx \
    rdollsgroup-odb.hxx \
    rdollsleaf-odb.hxx \
    driver.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