From 59fc1102f304e3d103eaa5d9cd69acb7402efc28 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 6 Dec 2012 20:02:08 +0100 Subject: add QCoreApplication to bootstrap lib this required making it compile with QT_NO_QOBJECT. of course this disables anything related to threading and event processing. needed for bootstrapping qmldevtools (qmlmin, lupdate) Change-Id: I6f8bd3996ac7b6eee49a5b8a55143d358abe35ee Reviewed-by: Joerg Bornemann Reviewed-by: Oswald Buddenhagen --- src/corelib/kernel/qcoreapplication.cpp | 101 +++++++++++++++++++++++++--- src/corelib/kernel/qcoreapplication.h | 33 ++++++++- src/corelib/kernel/qcoreapplication_p.h | 46 +++++++++---- src/corelib/kernel/qcoreapplication_win.cpp | 8 ++- 4 files changed, 160 insertions(+), 28 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index d89df92bdb..3540e3163d 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -42,9 +42,11 @@ #include "qcoreapplication.h" #include "qcoreapplication_p.h" +#ifndef QT_NO_QOBJECT #include "qabstracteventdispatcher.h" #include "qcoreevent.h" #include "qeventloop.h" +#endif #include "qcorecmdlineargs_p.h" #include #include @@ -55,10 +57,12 @@ #include #include #include +#ifndef QT_NO_QOBJECT #include #include #include #include +#endif #include #include #include @@ -66,6 +70,7 @@ #include #include +#ifndef QT_NO_QOBJECT #if defined(Q_OS_UNIX) # if defined(Q_OS_BLACKBERRY) # include "qeventdispatcher_blackberry_p.h" @@ -78,10 +83,10 @@ # include "qeventdispatcher_unix_p.h" # endif #endif - #ifdef Q_OS_WIN # include "qeventdispatcher_win_p.h" #endif +#endif // QT_NO_QOBJECT #ifdef Q_OS_MAC # include "qcore_mac_p.h" @@ -91,6 +96,7 @@ #ifdef Q_OS_UNIX # include +# include #endif #ifdef Q_OS_VXWORKS @@ -99,6 +105,7 @@ QT_BEGIN_NAMESPACE +#ifndef QT_NO_QOBJECT class QMutexUnlocker { public: @@ -113,6 +120,7 @@ private: QMutex *mtx; }; +#endif #if defined(Q_OS_WIN) || defined(Q_OS_MAC) extern QString qAppFileName(); @@ -183,12 +191,14 @@ void QCoreApplicationPrivate::processCommandLineArguments() // Support for introspection +#ifndef QT_NO_QOBJECT QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set = { 0, 0, 0, 0 }; void qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set) { qt_signal_spy_callback_set = callback_set; } +#endif extern "C" void Q_CORE_EXPORT qt_startup_hook() { @@ -198,7 +208,9 @@ typedef QList QStartUpFuncList; Q_GLOBAL_STATIC(QStartUpFuncList, preRList) typedef QList QVFuncList; Q_GLOBAL_STATIC(QVFuncList, postRList) +#ifndef QT_NO_QOBJECT static QBasicMutex globalPreRoutinesMutex; +#endif /*! \internal @@ -269,12 +281,15 @@ void Q_CORE_EXPORT qt_call_post_routines() } +// initialized in qcoreapplication and in qtextstream autotest when setlocale is called. +static bool qt_locale_initialized = false; + +#ifndef QT_NO_QOBJECT + // app starting up if false bool QCoreApplicationPrivate::is_app_running = false; // app closing down if true bool QCoreApplicationPrivate::is_app_closing = false; -// initialized in qcoreapplication and in qtextstream autotest when setlocale is called. -static bool qt_locale_initialized = false; Q_CORE_EXPORT uint qGlobalPostedEventsCount() { @@ -282,14 +297,17 @@ Q_CORE_EXPORT uint qGlobalPostedEventsCount() return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; } -QCoreApplication *QCoreApplication::self = 0; QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0; -uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents); #ifdef Q_OS_UNIX Qt::HANDLE qt_application_thread_id = 0; #endif +#endif // QT_NO_QOBJECT + +QCoreApplication *QCoreApplication::self = 0; +uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents); + struct QCoreApplicationData { QCoreApplicationData() { #ifndef QT_NO_LIBRARY @@ -341,20 +359,29 @@ struct QCoreApplicationData { Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata) +#ifndef QT_NO_QOBJECT static bool quitLockRefEnabled = true; +#endif QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint flags) - : QObjectPrivate() - , argc(aargc) + : +#ifndef QT_NO_QOBJECT + QObjectPrivate(), +#endif + argc(aargc) , argv(aargv) #ifdef Q_OS_WIN , origArgc(aargc) , origArgv(new char *[aargc]) #endif , application_type(0) +#ifndef QT_NO_QOBJECT , in_exec(false) , aboutToQuitEmitted(false) , threadData_clean(false) +#else + , q_ptr(0) +#endif { app_compile_version = flags & 0xffffff; static const char *const empty = ""; @@ -362,27 +389,35 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint argc = 0; argv = (char **)∅ // ouch! careful with QCoreApplication::argv()! } +#ifdef Q_OS_WIN + qCopy(argv, argv + argc, origArgv); +#endif + +#ifndef QT_NO_QOBJECT QCoreApplicationPrivate::is_app_closing = false; -#if defined(Q_OS_UNIX) +# if defined(Q_OS_UNIX) qt_application_thread_id = QThread::currentThreadId(); -#elif defined(Q_OS_WIN) - qCopy(argv, argv + argc, origArgv); -#endif +# endif // note: this call to QThread::currentThread() may end up setting theMainThread! if (QThread::currentThread() != theMainThread) qWarning("WARNING: QApplication was not created in the main() thread."); +#endif } QCoreApplicationPrivate::~QCoreApplicationPrivate() { +#ifndef QT_NO_QOBJECT cleanupThreadData(); +#endif #ifdef Q_OS_WIN delete [] origArgv; #endif } +#ifndef QT_NO_QOBJECT + void QCoreApplicationPrivate::cleanupThreadData() { if (threadData && !threadData_clean) { @@ -455,6 +490,8 @@ void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver) } #endif +#endif // QT_NO_QOBJECT + void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths() { #ifndef QT_NO_LIBRARY @@ -576,13 +613,18 @@ void QCoreApplicationPrivate::initLocale() \internal */ QCoreApplication::QCoreApplication(QCoreApplicationPrivate &p) +#ifdef QT_NO_QOBJECT + : d_ptr(&p) +#else : QObject(p, 0) +#endif { init(); // note: it is the subclasses' job to call // QCoreApplicationPrivate::eventDispatcher->startingUp(); } +#ifndef QT_NO_QOBJECT /*! Flushes the platform specific event queues. @@ -599,6 +641,7 @@ void QCoreApplication::flush() if (self && self->d_func()->eventDispatcher) self->d_func()->eventDispatcher->flush(); } +#endif /*! Constructs a Qt kernel application. Kernel applications are @@ -619,16 +662,23 @@ QCoreApplication::QCoreApplication(int &argc, char **argv , int _internal #endif ) +#ifdef QT_NO_QOBJECT + : d_ptr(new QCoreApplicationPrivate(argc, argv, _internal)) +#else : QObject(*new QCoreApplicationPrivate(argc, argv, _internal)) +#endif { init(); +#ifndef QT_NO_QOBJECT QCoreApplicationPrivate::eventDispatcher->startingUp(); +#endif } // ### move to QCoreApplicationPrivate constructor? void QCoreApplication::init() { + d_ptr->q_ptr = this; Q_D(QCoreApplication); QCoreApplicationPrivate::initLocale(); @@ -636,6 +686,7 @@ void QCoreApplication::init() Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object"); QCoreApplication::self = this; +#ifndef QT_NO_QOBJECT // use the event dispatcher created by the app programmer (if any) if (!QCoreApplicationPrivate::eventDispatcher) QCoreApplicationPrivate::eventDispatcher = d->threadData->eventDispatcher; @@ -650,17 +701,20 @@ void QCoreApplication::init() } d->threadData->eventDispatcher = QCoreApplicationPrivate::eventDispatcher; +#endif #ifndef QT_NO_LIBRARY if (coreappdata()->app_libpaths) d->appendApplicationPathToLibraryPaths(); #endif +#ifndef QT_NO_QOBJECT #if defined(Q_OS_UNIX) && !(defined(QT_NO_PROCESS)) // Make sure the process manager thread object is created in the main // thread. QProcessPrivate::initializeProcessManager(); #endif +#endif #ifdef QT_EVAL extern void qt_core_eval_init(uint); @@ -681,8 +735,10 @@ QCoreApplication::~QCoreApplication() qt_call_post_routines(); self = 0; +#ifndef QT_NO_QOBJECT QCoreApplicationPrivate::is_app_closing = true; QCoreApplicationPrivate::is_app_running = false; +#endif #if !defined(QT_NO_THREAD) // Synchronize and stop the global thread pool threads. @@ -696,10 +752,12 @@ QCoreApplication::~QCoreApplication() globalThreadPool->waitForDone(); #endif +#ifndef QT_NO_QOBJECT d_func()->threadData->eventDispatcher = 0; if (QCoreApplicationPrivate::eventDispatcher) QCoreApplicationPrivate::eventDispatcher->closingDown(); QCoreApplicationPrivate::eventDispatcher = 0; +#endif #ifndef QT_NO_LIBRARY delete coreappdata()->app_libpaths; @@ -741,6 +799,8 @@ bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute) } +#ifndef QT_NO_QOBJECT + /*! \property QCoreApplication::quitLockEnabled @@ -1603,6 +1663,8 @@ void QCoreApplication::quit() \sa quit() */ +#endif // QT_NO_QOBJECT + #ifndef QT_NO_TRANSLATION /*! Adds the translation file \a translationFile to the list of @@ -1644,8 +1706,11 @@ bool QCoreApplication::installTranslator(QTranslator *translationFile) return false; #endif +#ifndef QT_NO_QOBJECT QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev); +#endif + return true; } @@ -1667,10 +1732,12 @@ bool QCoreApplication::removeTranslator(QTranslator *translationFile) return false; QCoreApplicationPrivate *d = self->d_func(); if (d->translators.removeAll(translationFile)) { +#ifndef QT_NO_QOBJECT if (!self->closingDown()) { QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev); } +#endif return true; } return false; @@ -2058,8 +2125,10 @@ void QCoreApplication::setOrganizationName(const QString &orgName) if (coreappdata()->orgName == orgName) return; coreappdata()->orgName = orgName; +#ifndef QT_NO_QOBJECT if (QCoreApplication::self) emit QCoreApplication::self->organizationNameChanged(); +#endif } QString QCoreApplication::organizationName() @@ -2096,8 +2165,10 @@ void QCoreApplication::setOrganizationDomain(const QString &orgDomain) if (coreappdata()->orgDomain == orgDomain) return; coreappdata()->orgDomain = orgDomain; +#ifndef QT_NO_QOBJECT if (QCoreApplication::self) emit QCoreApplication::self->organizationDomainChanged(); +#endif } QString QCoreApplication::organizationDomain() @@ -2128,8 +2199,10 @@ void QCoreApplication::setApplicationName(const QString &application) if (coreappdata()->application == application) return; coreappdata()->application = application; +#ifndef QT_NO_QOBJECT if (QCoreApplication::self) emit QCoreApplication::self->applicationNameChanged(); +#endif } QString QCoreApplication::applicationName() @@ -2167,8 +2240,10 @@ void QCoreApplication::setApplicationVersion(const QString &version) if (coreappdata()->applicationVersion == version) return; coreappdata()->applicationVersion = version; +#ifndef QT_NO_QOBJECT if (QCoreApplication::self) emit QCoreApplication::self->applicationVersionChanged(); +#endif } QString QCoreApplication::applicationVersion() @@ -2317,6 +2392,8 @@ void QCoreApplication::removeLibraryPath(const QString &path) #endif //QT_NO_LIBRARY +#ifndef QT_NO_QOBJECT + /*! Installs an event filter \a filterObj for all native events received by the application in the main thread. @@ -2412,6 +2489,8 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc mainThread->setEventDispatcher(eventDispatcher); } +#endif // QT_NO_QOBJECT + /*! \macro Q_COREAPP_STARTUP_FUNCTION(QtStartUpFunction ptr) \since 5.1 diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index 9f9a1c14fd..ae17aeec0e 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -42,13 +42,21 @@ #ifndef QCOREAPPLICATION_H #define QCOREAPPLICATION_H +#include +#include +#ifndef QT_NO_QOBJECT #include #include #include +#else +#include +#endif +#ifndef QT_NO_QOBJECT #if defined(Q_OS_WIN) && !defined(tagMSG) typedef struct tagMSG MSG; #endif +#endif QT_BEGIN_NAMESPACE @@ -63,14 +71,19 @@ class QAbstractNativeEventFilter; #define qApp QCoreApplication::instance() -class Q_CORE_EXPORT QCoreApplication : public QObject +class Q_CORE_EXPORT QCoreApplication +#ifndef QT_NO_QOBJECT + : public QObject +#endif { +#ifndef QT_NO_QOBJECT Q_OBJECT Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged) Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged) Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged) Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged) Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled) +#endif Q_DECLARE_PRIVATE(QCoreApplication) public: @@ -101,6 +114,7 @@ public: static QCoreApplication *instance() { return self; } +#ifndef QT_NO_QOBJECT static int exec(); static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime); @@ -118,6 +132,7 @@ public: static bool startingUp(); static bool closingDown(); +#endif static QString applicationDirPath(); static QString applicationFilePath(); @@ -146,6 +161,7 @@ public: { return translate(context, key, disambiguation, n); } #endif +#ifndef QT_NO_QOBJECT static void flush(); void installNativeEventFilter(QAbstractNativeEventFilter *filterObj); @@ -173,13 +189,20 @@ protected: bool event(QEvent *); virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *); +#endif // QT_NO_QOBJECT protected: QCoreApplication(QCoreApplicationPrivate &p); +#ifdef QT_NO_QOBJECT + QScopedPointer d_ptr; +#endif + private: +#ifndef QT_NO_QOBJECT static bool sendSpontaneousEvent(QObject *receiver, QEvent *event); bool notifyInternal(QObject *receiver, QEvent *event); +#endif void init(); @@ -187,7 +210,6 @@ private: Q_DISABLE_COPY(QCoreApplication) - friend class QEventDispatcherUNIXPrivate; friend class QApplication; friend class QApplicationPrivate; friend class QGuiApplication; @@ -196,17 +218,22 @@ private: friend class QWidget; friend class QWidgetWindow; friend class QWidgetPrivate; +#ifndef QT_NO_QOBJECT + friend class QEventDispatcherUNIXPrivate; friend class QCocoaEventDispatcherPrivate; friend bool qt_sendSpontaneousEvent(QObject*, QEvent*); +#endif friend Q_CORE_EXPORT QString qAppName(); friend class QClassFactory; }; +#ifndef QT_NO_QOBJECT inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event) { if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; } inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event) { if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; } +#endif #ifdef QT_NO_DEPRECATED # define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) @@ -237,10 +264,12 @@ Q_CORE_EXPORT QString qAppName(); // get application name } \ Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function) +#ifndef QT_NO_QOBJECT #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 &); #endif +#endif QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index 36ba0663b7..563a3b2093 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -56,7 +56,9 @@ #include "QtCore/qcoreapplication.h" #include "QtCore/qtranslator.h" #include "QtCore/qsettings.h" +#ifndef QT_NO_QOBJECT #include "private/qobject_p.h" +#endif QT_BEGIN_NAMESPACE @@ -64,7 +66,10 @@ typedef QList QTranslatorList; class QAbstractEventDispatcher; -class Q_CORE_EXPORT QCoreApplicationPrivate : public QObjectPrivate +class Q_CORE_EXPORT QCoreApplicationPrivate +#ifndef QT_NO_QOBJECT + : public QObjectPrivate +#endif { Q_DECLARE_PUBLIC(QCoreApplication) @@ -77,23 +82,27 @@ public: QCoreApplicationPrivate(int &aargc, char **aargv, uint flags); ~QCoreApplicationPrivate(); + QString appName() const; + +#ifdef Q_OS_MAC + static QString macMenuBarName(); +#endif + + static void initLocale(); + + static bool checkInstance(const char *method); + +#ifndef QT_NO_QOBJECT bool sendThroughApplicationEventFilters(QObject *, QEvent *); bool sendThroughObjectEventFilters(QObject *, QEvent *); bool notify_helper(QObject *, QEvent *); - QString appName() const; virtual void createEventDispatcher(); static void removePostedEvent(QEvent *); #ifdef Q_OS_WIN static void removePostedTimerEvent(QObject *object, int timerId); #endif -#ifdef Q_OS_MAC - static QString macMenuBarName(); -#endif - - static void initLocale(); - QAtomicInt quitLockRef; void ref(); void deref(); @@ -104,12 +113,14 @@ public: static QThread *theMainThread; static QThread *mainThread(); - static bool checkInstance(const char *method); static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); #if !defined (QT_NO_DEBUG) || defined (QT_MAC_FRAMEWORK_BUILD) void checkReceiverThread(QObject *receiver); #endif + void cleanupThreadData(); +#endif // QT_NO_QOBJECT + int &argc; char **argv; #ifdef Q_OS_WIN @@ -117,24 +128,27 @@ public: char **origArgv; // store unmodified arguments for QCoreApplication::arguments() #endif void appendApplicationPathToLibraryPaths(void); - void cleanupThreadData(); #ifndef QT_NO_TRANSLATION QTranslatorList translators; + + static bool isTranslatorInstalled(QTranslator *translator); #endif + uint application_type; - bool in_exec; - bool aboutToQuitEmitted; - bool threadData_clean; QString cachedApplicationDirPath; QString cachedApplicationFilePath; - static bool isTranslatorInstalled(QTranslator *translator); +#ifndef QT_NO_QOBJECT + bool in_exec; + bool aboutToQuitEmitted; + bool threadData_clean; static QAbstractEventDispatcher *eventDispatcher; static bool is_app_running; static bool is_app_closing; +#endif static uint attribs; static inline bool testAttribute(uint flag) { return attribs & (1 << flag); } @@ -143,6 +157,10 @@ public: void processCommandLineArguments(); QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. inline QString qmljsDebugArgumentsString() { return qmljs_debug_arguments; } + +#ifdef QT_NO_QOBJECT + QCoreApplication *q_ptr; +#endif }; QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 3cb89e8fcd..93e45d3984 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -43,10 +43,12 @@ #include "qcoreapplication_p.h" #include "qstringlist.h" #include "qvector.h" -#include "qmutex.h" #include "qfileinfo.h" #include "qcorecmdlineargs_p.h" +#ifndef QT_NO_QOBJECT +#include "qmutex.h" #include +#endif #include #include @@ -157,6 +159,8 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, Q_UNUSED(prevInstance); } +#ifndef QT_NO_QOBJECT + void QCoreApplicationPrivate::removePostedTimerEvent(QObject *object, int timerId) { QThreadData *data = object->d_func()->threadData; @@ -996,4 +1000,6 @@ QDebug operator<<(QDebug dbg, const MSG &msg) } #endif +#endif // QT_NO_QOBJECT + QT_END_NAMESPACE -- cgit v1.2.3