summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index ec808424f9..1696aeb77b 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -194,8 +194,32 @@ extern "C" void Q_CORE_EXPORT qt_startup_hook()
{
}
+typedef QList<QtStartUpFunction> QStartUpFuncList;
+Q_GLOBAL_STATIC(QStartUpFuncList, preRList)
typedef QList<QtCleanUpFunction> QVFuncList;
Q_GLOBAL_STATIC(QVFuncList, postRList)
+static QBasicMutex globalPreRoutinesMutex;
+
+/*!
+ \internal
+
+ Adds a global routine that will be called from the QCoreApplication
+ constructor. The public API is Q_COREAPP_STARTUP_FUNCTION.
+*/
+void qAddPreRoutine(QtStartUpFunction p)
+{
+ QStartUpFuncList *list = preRList();
+ if (!list)
+ return;
+ // Due to C++11 parallel dynamic initialization, this can be called
+ // from multiple threads.
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(&globalPreRoutinesMutex);
+#endif
+ if (QCoreApplication::instance())
+ p();
+ list->prepend(p); // in case QCoreApplication is re-created, see qt_call_pre_routines
+}
void qAddPostRoutine(QtCleanUpFunction p)
{
@@ -213,6 +237,21 @@ void qRemovePostRoutine(QtCleanUpFunction p)
list->removeAll(p);
}
+static void qt_call_pre_routines()
+{
+ QStartUpFuncList *list = preRList();
+ if (!list)
+ return;
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(&globalPreRoutinesMutex);
+#endif
+ // Unlike qt_call_post_routines, we don't empty the list, because
+ // Q_COREAPP_STARTUP_FUNCTION is a macro, so the user expects
+ // the function to be executed every time QCoreApplication is created.
+ for (int i = 0; i < list->count(); ++i)
+ list->at(i)();
+}
+
void Q_CORE_EXPORT qt_call_post_routines()
{
QVFuncList *list = 0;
@@ -637,6 +676,7 @@ void QCoreApplication::init()
d->processCommandLineArguments();
+ qt_call_pre_routines();
qt_startup_hook();
}
@@ -1999,9 +2039,21 @@ QStringList QCoreApplication::arguments()
\sa organizationDomain, applicationName
*/
+/*!
+ \fn void QCoreApplication::organizationNameChanged()
+ \internal
+
+ While not useful from C++ due to how organizationName is normally set once on
+ startup, this is still needed for QML so that bindings are reevaluated after
+ that initial change.
+*/
void QCoreApplication::setOrganizationName(const QString &orgName)
{
+ if (coreappdata()->orgName == orgName)
+ return;
coreappdata()->orgName = orgName;
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->organizationNameChanged();
}
QString QCoreApplication::organizationName()
@@ -2027,9 +2079,19 @@ QString QCoreApplication::organizationName()
\sa organizationName, applicationName, applicationVersion
*/
+/*!
+ \fn void QCoreApplication::organizationDomainChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setOrganizationDomain(const QString &orgDomain)
{
+ if (coreappdata()->orgDomain == orgDomain)
+ return;
coreappdata()->orgDomain = orgDomain;
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->organizationDomainChanged();
}
QString QCoreApplication::organizationDomain()
@@ -2049,9 +2111,19 @@ QString QCoreApplication::organizationDomain()
\sa organizationName, organizationDomain, applicationVersion, applicationFilePath
*/
+/*!
+ \fn void QCoreApplication::applicationNameChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setApplicationName(const QString &application)
{
+ if (coreappdata()->application == application)
+ return;
coreappdata()->application = application;
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->applicationNameChanged();
}
QString QCoreApplication::applicationName()
@@ -2078,9 +2150,19 @@ Q_CORE_EXPORT QString qt_applicationName_noFallback()
\sa applicationName, organizationName, organizationDomain
*/
+/*!
+ \fn void QCoreApplication::applicationVersionChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setApplicationVersion(const QString &version)
{
+ if (coreappdata()->applicationVersion == version)
+ return;
coreappdata()->applicationVersion = version;
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->applicationVersionChanged();
}
QString QCoreApplication::applicationVersion()
@@ -2325,6 +2407,31 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
}
/*!
+ \macro Q_COREAPP_STARTUP_FUNCTION(QtStartUpFunction ptr)
+ \since 5.1
+ \relates QCoreApplication
+ \reentrant
+
+ Adds a global function that will be called from the QCoreApplication
+ constructor. This macro is normally used to initialize libraries
+ for program-wide functionality, without requiring the application to
+ call into the library for initialization.
+
+ The function specified by \a ptr should take no arguments and should
+ return nothing. For example:
+
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 3
+
+ Note that the startup function will run at the end of the QCoreApplication constructor,
+ before any GUI initialization. If GUI code is required in the function,
+ use a timer (or a queued invocation) to perform the initialization later on,
+ from the event loop.
+
+ If QCoreApplication is deleted and another QCoreApplication is created,
+ the startup function will be invoked again.
+*/
+
+/*!
\fn void qAddPostRoutine(QtCleanUpFunction ptr)
\relates QCoreApplication