summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>2012-12-06 20:02:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-14 19:49:38 +0100
commit59fc1102f304e3d103eaa5d9cd69acb7402efc28 (patch)
treef46776946ae406d216d6f06c1889539c47da94da /src/corelib/kernel/qcoreapplication.cpp
parente6aba2f7cd02e5b268eb764765dc935bd8ba05a3 (diff)
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 <joerg.bornemann@digia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp101
1 files changed, 90 insertions, 11 deletions
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 <qdatastream.h>
#include <qdebug.h>
@@ -55,10 +57,12 @@
#include <private/qprocess_p.h>
#include <qstandardpaths.h>
#include <qtextcodec.h>
+#ifndef QT_NO_QOBJECT
#include <qthread.h>
#include <qthreadpool.h>
#include <qthreadstorage.h>
#include <private/qthread_p.h>
+#endif
#include <qelapsedtimer.h>
#include <qlibraryinfo.h>
#include <qvarlengtharray.h>
@@ -66,6 +70,7 @@
#include <private/qfunctions_p.h>
#include <private/qlocale_p.h>
+#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 <locale.h>
+# include <unistd.h>
#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<QtStartUpFunction> QStartUpFuncList;
Q_GLOBAL_STATIC(QStartUpFuncList, preRList)
typedef QList<QtCleanUpFunction> 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 **)&empty; // 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