From d147285d644157bc12487584578b5389b56eea31 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 14 Jan 2013 12:58:31 +0100 Subject: Add Q_COREAPP_STARTUP_FUNCTION macro. This is necessary for initializing things in a library, which require a QCoreApplication instance (unlike Q_CONSTRUCTOR_FUNCTION, which runs before that). Example use cases: KCrash (segv handler), and KCheckAccelerators (debugging tool triggered by magic key combination). Change-Id: I5f4c4699dd4d21aea72b007989ba57467e86ed10 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/corelib/kernel/qcoreapplication.h') diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 185aea53d1..0dfad6f23e 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -220,12 +220,20 @@ public: \ { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \ private: +typedef void (*QtStartUpFunction)(); typedef void (*QtCleanUpFunction)(); +Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction); Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction); Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction); Q_CORE_EXPORT QString qAppName(); // get application name +#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \ + static void AFUNC ## _ctor_function() { \ + qAddPreRoutine(AFUNC); \ + } \ + Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function) + #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT QString decodeMSG(const MSG &); Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &); -- cgit v1.2.3