diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-01-31 17:35:00 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-09 00:32:41 +0100 |
commit | 0c978407088fdbd15dc185aef7506087a88e1443 (patch) | |
tree | a8b2e21e5cd52fa615fce085acbe4439782bf365 /src | |
parent | 14577726ee97c8d6dd176e0039ab2da0193c7bb1 (diff) |
Introduce Q_DECLARE_OPAQUE_POINTER
To hide the IsPointerToTypeDerivedFromQObject monstruosity :-)
Documentation for Q_DECLARE_METATYPE and qRegisterMetaType was updated
to mention requirements on registered types and how they can be
circumvented for pointer types with the new macro.
Change-Id: If83b037a8e2f28761eb903525e87008107298801
Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 20 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 10 | ||||
-rw-r--r-- | src/sql/drivers/psql/qsql_psql.cpp | 12 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 12 | ||||
-rw-r--r-- | src/sql/drivers/sqlite2/qsql_sqlite2.cpp | 11 | ||||
-rw-r--r-- | src/sql/drivers/tds/qsql_tds.cpp | 15 |
6 files changed, 40 insertions, 40 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 6a7c5c2a34..d965c48255 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -116,6 +116,16 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals #endif } // namespace +/*! + \macro Q_DECLARE_OPAQUE_POINTER(Pointer) + \relates QMetaType + + This macro enables pointers to forward-declared types to be registered with + QMetaType using either Q_DECLARE_METATYPE() or qRegisterMetaType(). + + \sa Q_DECLARE_METATYPE(), qRegisterMetaType() + +*/ /*! \macro Q_DECLARE_METATYPE(Type) @@ -126,6 +136,11 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals a public destructor. It is needed to use the type \a Type as a custom type in QVariant. + This macro requires that \a Type is a fully defined type at the point where + it is used. For pointer types, it also requires that the pointed to type is + fully defined. Use in conjunction with Q_DECLARE_OPAQUE_POINTER() to + register pointers to forward declared types. + Ideally, this macro should be placed below the declaration of the class or struct. If that is not possible, it can be put in a private header file which has to be included every time that @@ -1630,6 +1645,11 @@ QMetaType::TypeFlags QMetaType::typeFlags(int type) public default constructor, a public copy constructor and a public destructor can be registered. + This function requires that \c{T} is a fully defined type at the point + where the function is called. For pointer types, it also requires that the + pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able + to register pointers to forward declared types. + After a type has been registered, you can create and destroy objects of that type dynamically at run-time. diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index fd27bb81de..9e702298c1 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -471,6 +471,16 @@ inline int qRegisterMetaTypeStreamOperators() } #endif +#define Q_DECLARE_OPAQUE_POINTER(POINTER) \ + QT_BEGIN_NAMESPACE namespace QtPrivate { \ + template <> \ + struct IsPointerToTypeDerivedFromQObject<POINTER > \ + { \ + enum { Value = false }; \ + }; \ + } QT_END_NAMESPACE \ + /**/ + #define Q_DECLARE_METATYPE(TYPE) \ QT_BEGIN_NAMESPACE \ template <> \ diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index e3533581ba..ec31d54f0f 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -107,18 +107,10 @@ template <typename T> inline void PQfreemem(T *t, int = 0) { free(t); } -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<PGconn*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE +Q_DECLARE_OPAQUE_POINTER(PGconn*) Q_DECLARE_METATYPE(PGconn*) -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<PGresult*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE +Q_DECLARE_OPAQUE_POINTER(PGresult*) Q_DECLARE_METATYPE(PGresult*) QT_BEGIN_NAMESPACE diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 962fc97dfc..d2dc5af070 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -59,18 +59,10 @@ #include <sqlite3.h> -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<sqlite3*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE +Q_DECLARE_OPAQUE_POINTER(sqlite3*) Q_DECLARE_METATYPE(sqlite3*) -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<sqlite3_stmt*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE +Q_DECLARE_OPAQUE_POINTER(sqlite3_stmt*) Q_DECLARE_METATYPE(sqlite3_stmt*) QT_BEGIN_NAMESPACE diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp index 46127923bf..b42f82e800 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp @@ -60,15 +60,10 @@ typedef struct sqlite_vm sqlite_vm; -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<sqlite_vm*> { - enum { Value = false }; -}; -template <> struct IsPointerToTypeDerivedFromQObject<sqlite*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE +Q_DECLARE_OPAQUE_POINTER(sqlite_vm*) Q_DECLARE_METATYPE(sqlite_vm*) + +Q_DECLARE_OPAQUE_POINTER(sqlite*) Q_DECLARE_METATYPE(sqlite*) QT_BEGIN_NAMESPACE diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp index 2a97a3c392..b9414499d8 100644 --- a/src/sql/drivers/tds/qsql_tds.cpp +++ b/src/sql/drivers/tds/qsql_tds.cpp @@ -63,6 +63,9 @@ #include <stdlib.h> +Q_DECLARE_OPAQUE_POINTER(LOGINREC*) +Q_DECLARE_OPAQUE_POINTER(DBPROCESS*) + QT_BEGIN_NAMESPACE #ifdef DBNTWIN32 @@ -127,18 +130,6 @@ QT_BEGIN_NAMESPACE #define CS_PUBLIC #endif -namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<LOGINREC*> { - enum { Value = false }; -}; -} - -namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<DBPROCESS*> { - enum { Value = false }; -}; -} - QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, int errNo = -1) { return QSqlError(QLatin1String("QTDS: ") + err, QString(), type, errNo); |