From 839a84b996d89dcf3d553af23e4ed5e0e4fa60e2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 4 Aug 2011 13:33:21 +0200 Subject: Add support for Qt QSharedPointer as value wrapper --- qt/common/smart-ptr/driver.cxx | 25 +++++++++++++++++++++++++ qt/common/smart-ptr/test.hxx | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'qt') diff --git a/qt/common/smart-ptr/driver.cxx b/qt/common/smart-ptr/driver.cxx index ee53c57..49e2ae1 100644 --- a/qt/common/smart-ptr/driver.cxx +++ b/qt/common/smart-ptr/driver.cxx @@ -212,6 +212,31 @@ main (int argc, char* argv[]) t.commit (); } + + // + // Test QSharedPointer as a value wrapper. + // + + { + obj2 o1 (1); + obj2 o2 (2); + o2.num = QSharedPointer (new unsigned long (123)); + + transaction t (db->begin ()); + db->persist (o1); + db->persist (o2); + t.commit (); + } + + { + transaction t (db->begin ()); + QSharedPointer o1 (db->load (1)); + QSharedPointer o2 (db->load (2)); + t.commit (); + + assert (!o1->num); + assert (o2->num && *o2->num == 123); + } } catch (const odb::exception& e) { diff --git a/qt/common/smart-ptr/test.hxx b/qt/common/smart-ptr/test.hxx index 0a4ce03..86e4fba 100644 --- a/qt/common/smart-ptr/test.hxx +++ b/qt/common/smart-ptr/test.hxx @@ -8,6 +8,8 @@ #include +#include + #include #include @@ -53,4 +55,25 @@ struct obj QLazySharedPointer c; }; +// Test QSharedPointer as a value wrapper. +// +#pragma db object +struct obj2 +{ + obj2 () + { + } + + obj2 (unsigned long id) + : id (id) + { + } + + #pragma db id + unsigned long id; + + #pragma db null + QSharedPointer num; +}; + #endif // TEST_HXX -- cgit v1.1