[odb-users] Proper way to reload QLazySharedPointer objects within a session

Rene Jensen rene at catatonic.dk
Wed Jun 6 08:30:57 EDT 2012

Hi odb-list.

I am trying to map a hierachy of objects into a Qt tree view model. In
order to keep potential problems to a minimum, I decided that whenever
 anything is changed, all data should simple be reloaded.

My database object is trivial:

#pragma db object session
#pragma db object table("my_table_name")
#pragma db object pointer(QSharedPointer)

class MyObject: public ProxyBase
    friend class odb::access;

    #pragma db id  auto
    qint32 id;

    #pragma db null
    #pragma db column("super_id")
    QLazySharedPointer<MyObject> supergroup;

    #pragma db value_not_null inverse(supergroup)
    QList<QLazyWeakPointer<MyObject> >   subgroups;

... which clearly forms a tree. I recursively load all objects at
startup (again, to minimize chance of complications), and upon any
change, I want to reload everything. First I try to flush:
    foreach (MyObject_LazySharedPointer P, myPool.values()):


Trouble with duplicated instances forced me to use sessions. Now I
cannot properly reload the tree, even though I call
QLazySharedPointer::reload on all my instances:

        for (MyObject_Result::iterator I (result.begin()); I !=
result.end(); ++I)
            MyObject_LazySharedPointer P = I.load();
            db->reload (P.data());

            myPool[ P->id) ] = P;
            loadRecursively(P); // ... doing the same thing inside
loadRecursively: reload each subgroup...


A slightly confusing setup, I admit. Here's the question:

    Can database::reload be used to force a reload of an object that
is already owned by a QLazySharedPointer?
    Assuming I can't get rid of all QLazySharedPointers. Is there any
way to force a reload of those objects?

Best regards,
Rene Jensen

More information about the odb-users mailing list