#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)
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
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.
}
#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 <> \
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
#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
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
#include <stdlib.h>
+Q_DECLARE_OPAQUE_POINTER(LOGINREC*)
+Q_DECLARE_OPAQUE_POINTER(DBPROCESS*)
+
QT_BEGIN_NAMESPACE
#ifdef DBNTWIN32
#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);
}
class Forward;
-QT_BEGIN_NAMESPACE namespace QtPrivate {
-template <> struct IsPointerToTypeDerivedFromQObject<Forward*> {
- enum { Value = false };
-};
-} QT_END_NAMESPACE
-Q_DECLARE_METATYPE(Forward*);
+Q_DECLARE_OPAQUE_POINTER(Forward*)
+Q_DECLARE_METATYPE(Forward*)
void tst_QVariant::forwardDeclare()
{