15#include <private/qproperty_p.h>
23#include <private/qloggingregistry_p.h>
30#include <QtCore/qpromise.h>
32#include <private/qthread_p.h>
35#include <private/qthreadpool_p.h>
41#include <private/qfactoryloader_p.h>
42#include <private/qfunctions_p.h>
43#include <private/qlocale_p.h>
44#include <private/qlocking_p.h>
45#include <private/qhooks_p.h>
47#if QT_CONFIG(permissions)
48#include <private/qpermissions_p.h>
53# if defined(Q_OS_DARWIN)
56# if !defined(QT_NO_GLIB)
60# if !defined(Q_OS_WASM)
69#if defined(Q_OS_ANDROID)
70#include <QtCore/qjniobject.h>
81# ifndef Q_OS_INTEGRITY
85# include <sys/types.h>
90#if __has_include(<sys/auxv.h>)
99#include <emscripten/val.h>
102#ifdef QT_BOOTSTRAPPED
103#include <private/qtrace_p.h>
105#include <qtcore_tracepoints_p.h>
121 "#include <qcoreevent.h>"
131Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit,
bool consumed,
bool filtered);
133#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN)
139#if !defined(Q_OS_WIN)
141QString QCoreApplicationPrivate::infoDictionaryStringProperty(
const QString &propertyName)
144 QCFString cfPropertyName = propertyName.toCFString();
145 CFTypeRef
string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
148 bundleName = QString::fromCFString(
static_cast<CFStringRef
>(
string));
156 applicationName = infoDictionaryStringProperty(
QStringLiteral(
"CFBundleName"));
159 char *
p = strrchr(
argv[0],
'/');
163 return applicationName;
168#ifdef QT_BOOTSTRAPPED
169#elif defined(Q_OS_DARWIN)
170 applicationVersion = infoDictionaryStringProperty(
QStringLiteral(
"CFBundleVersion"));
171#elif defined(Q_OS_ANDROID)
175 "getPackageManager",
"()Landroid/content/pm/PackageManager;");
177 if (pm.isValid() && pn.isValid()) {
179 "getPackageInfo",
"(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;",
181 if (packageInfo.isValid()) {
182 QJniObject versionName = packageInfo.getObjectField(
183 "versionName",
"Ljava/lang/String;");
184 if (versionName.isValid())
185 return versionName.toString();
190 return applicationVersion;
198 bool b = (QCoreApplication::self !=
nullptr);
200 qWarning(
"QApplication::%s: Please instantiate the QApplication object first", function);
204#if QT_CONFIG(commandlineparser)
205void QCoreApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
208 QStringLiteral(
"Activates the QML/JS debugger with a specified port. The value must be of format port:1234[,block]. \"block\" makes the application wait for a connection."),
215 int j =
argc ? 1 : 0;
216 for (
int i = 1;
i <
argc; ++
i) {
219 if (*
argv[
i] !=
'-') {
226 if (strncmp(
arg,
"-qmljsdebugger=", 15) == 0) {
228 }
else if (strcmp(
arg,
"-qmljsdebugger") == 0 &&
i <
argc - 1) {
305 if (!preRList.exists())
322 if (!postRList.exists())
384#if QT_CONFIG(library)
385 std::unique_ptr<QStringList> app_libpaths;
386 std::unique_ptr<QStringList> manual_libpaths;
403static inline bool isArgvModified(
int argc,
char **argv)
405 if (__argc != argc || !__argv )
409 for (
int a = 0;
a < argc; ++
a) {
410 if (argv[
a] != __argv[
a] && strcmp(argv[
a], __argv[
a]))
416static inline bool contains(
int argc,
char **argv,
const char *needle)
418 for (
int a = 0;
a < argc; ++
a) {
419 if (!strcmp(argv[
a], needle))
440 , aboutToQuitEmitted(
false)
441 , threadData_clean(
false)
446 static const char *
const empty =
"";
449 argv =
const_cast<char **
>(&empty);
454 origArgv =
new char *[
argc];
462# if defined(Q_OS_UNIX)
464 qFatal(
"FATAL: The application binary appears to be running setuid, this is a security hole.");
469 qWarning(
"WARNING: QApplication was not created in the main() thread.");
480 if (consoleAllocated)
494 void *
data = &thisThreadData->tls;
495 QThreadStorageData::finish((
void **)
data);
499 const auto locker = qt_scoped_lock(thisThreadData->postEventList.mutex);
500 for (
const QPostEvent &pe : std::as_const(thisThreadData->postEventList)) {
502 --pe.receiver->d_func()->postedEvents;
503 pe.event->m_posted =
false;
507 thisThreadData->postEventList.clear();
508 thisThreadData->postEventList.recursion = 0;
509 thisThreadData->quitNow =
false;
540 return data->requiresCoreApplication;
548 "QCoreApplication::sendEvent",
550 "Current thread 0x%p. Receiver '%ls' (of type '%s') was created in thread 0x%p",
552 receiver->metaObject()->className(), thr)
553 .toLocal8Bit().data());
562#if QT_CONFIG(library)
563 QStringList *app_libpaths = coreappdata()->app_libpaths.get();
565 coreappdata()->app_libpaths.reset(app_libpaths =
new QStringList);
567 app_location.truncate(app_location.lastIndexOf(u
'/'));
569 if (
QFile::exists(app_location) && !app_libpaths->contains(app_location))
570 app_libpaths->
append(app_location);
588 if (AllocConsole() == FALSE)
590 consoleAllocated =
true;
594 if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::GetLastError() != ERROR_ACCESS_DENIED)
604 freopen_s(&
in,
"CONIN$",
"r", stdin);
605 freopen_s(&
out,
"CONOUT$",
"w", stdout);
606 freopen_s(&err,
"CONOUT$",
"w", stderr);
616#if defined(QT_BOOTSTRAPPED)
618#elif defined(Q_OS_UNIX)
619 Q_CONSTINIT
static bool qt_locale_initialized =
false;
620 if (qt_locale_initialized)
622 qt_locale_initialized =
true;
627 setlocale(LC_ALL,
"");
631# if defined(Q_OS_INTEGRITY)
632 setlocale(LC_CTYPE,
"UTF-8");
633# elif defined(Q_OS_QNX)
636# elif defined(Q_OS_ANDROID) && __ANDROID_API__ < __ANDROID_API_O__
639# elif defined(Q_OS_VXWORKS)
643 const std::string oldEncoding = nl_langinfo(CODESET);
645 ||
qstricmp(oldEncoding.data(),
"utf8") == 0)) {
646 const QByteArray oldLocale = setlocale(LC_ALL,
nullptr);
648 bool warnOnOverride =
true;
649# if defined(Q_OS_DARWIN)
653 warnOnOverride =
qstrcmp(setlocale(LC_CTYPE,
nullptr),
"C") != 0
654 || getenv(
"LC_ALL") || getenv(
"LC_CTYPE") || getenv(
"LANG");
658 newLocale = setlocale(LC_CTYPE,
"UTF-8");
660 newLocale = setlocale(LC_CTYPE,
nullptr);
662 newLocale.truncate(
dot);
664 newLocale.truncate(
at);
665 newLocale +=
".UTF-8";
666 newLocale = setlocale(LC_CTYPE, newLocale);
669 if (newLocale.isEmpty())
670 newLocale = setlocale(LC_CTYPE,
"C.UTF-8");
671 if (newLocale.isEmpty())
672 newLocale = setlocale(LC_CTYPE,
"C.utf8");
675 if (newLocale.isEmpty()) {
677 qWarning(
"Detected locale \"%s\" with character encoding \"%s\", which is not UTF-8.\n"
678 "Qt depends on a UTF-8 locale, but has failed to switch to one.\n"
679 "If this causes problems, reconfigure your locale. See the locale(1) manual\n"
680 "for more information.", oldLocale.constData(), oldEncoding.data());
681 }
else if (warnOnOverride) {
683 qWarning(
"Detected locale \"%s\" with character encoding \"%s\", which is not UTF-8.\n"
684 "Qt depends on a UTF-8 locale, and has switched to \"%s\" instead.\n"
685 "If this causes problems, reconfigure your locale. See the locale(1) manual\n"
686 "for more information.",
687 oldLocale.constData(), oldEncoding.data(), newLocale.constData());
790 d_func()->q_ptr =
this;
820 d_func()->q_ptr =
this;
838#if defined(Q_OS_MACOS)
848 Q_ASSERT_X(!QCoreApplication::self,
"QCoreApplication",
"there should be only one application object");
849 QCoreApplication::self =
q;
853 emscripten::val hardwareConcurrency = emscripten::val::global(
"navigator")[
"hardwareConcurrency"];
854 if (hardwareConcurrency.isUndefined())
855 QThreadPrivate::idealThreadCount = 2;
857 QThreadPrivate::idealThreadCount = hardwareConcurrency.as<
int>();
862 if (!coreappdata()->applicationNameSet)
863 coreappdata()->application =
appName();
865 if (!coreappdata()->applicationVersionSet)
866 coreappdata()->applicationVersion =
appVersion();
868#if defined(Q_OS_ANDROID)
876#if QT_CONFIG(library)
880 QStringList *appPaths = coreappdata()->app_libpaths.release();
881 QStringList *manualPaths = coreappdata()->manual_libpaths.release();
891 newPaths.prepend((*manualPaths)[--
i]);
892 }
else if (--
i < 0) {
893 newPaths.removeAll((*appPaths)[
j]);
894 }
else if ((*manualPaths)[
i] != (*appPaths)[
j]) {
895 newPaths.removeAll((*appPaths)[
j]);
900 coreappdata()->manual_libpaths.reset(
new QStringList(newPaths));
930#ifndef QT_BOOTSTRAPPED
966 if (globalThreadPool) {
967 globalThreadPool->waitForDone();
968 delete globalThreadPool;
971 guiThreadPool->waitForDone();
972 delete guiThreadPool;
977 d_func()->threadData.loadRelaxed()->eventDispatcher =
nullptr;
983#if QT_CONFIG(library)
984 coreappdata()->app_libpaths.reset();
985 coreappdata()->manual_libpaths.reset();
1050#if defined(QT_NO_QOBJECT)
1061#ifdef QT_BOOTSTRAPPED
1062 qWarning(
"Attribute %d must be set before QCoreApplication is created.",
1065 qWarning(
"Attribute Qt::%s must be set before QCoreApplication is created.",
1066 QMetaEnum::fromType<Qt::ApplicationAttribute>().valueToKey(
attribute));
1086#ifndef QT_NO_QOBJECT
1129 if (selfRequired && !self)
1150#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
1154 return self->notify(receiver,
event);
1166 if (
event && originatingEvent)
1167 event->m_spont = originatingEvent->m_spont;
1169 return notifyInternal2(receiver,
event);
1230#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
1231 Q_ASSERT(receiver->d_func()->threadData.loadAcquire()->
thread.loadRelaxed()
1246 if (receiver ==
nullptr) {
1247 qWarning(
"QCoreApplication::notify: Unexpected null receiver");
1265 for (
qsizetype i = 0;
i < extraData->eventFilters.size(); ++
i) {
1269 if (
obj->d_func()->threadData.loadRelaxed() != threadData.loadRelaxed()) {
1270 qWarning(
"QCoreApplication: Application event filter cannot be in a different thread.");
1273 if (
obj->eventFilter(receiver,
event))
1282 if ((receiver->d_func()->threadData.loadRelaxed()->
thread.loadAcquire() !=
mainThread()
1284 && receiver->d_func()->extraData) {
1285 for (
qsizetype i = 0;
i < receiver->d_func()->extraData->eventFilters.size(); ++
i) {
1286 QObject *
obj = receiver->d_func()->extraData->eventFilters.at(
i);
1289 if (
obj->d_func()->threadData.loadRelaxed() != receiver->d_func()->threadData.loadRelaxed()) {
1290 qWarning(
"QCoreApplication: Object event filter cannot be in a different thread.");
1293 if (
obj->eventFilter(receiver,
event))
1310 bool consumed =
false;
1311 bool filtered =
false;
1312 Q_TRACE_EXIT(QCoreApplication_notify_exit, consumed, filtered);
1315 if (receiver->d_func()->threadData.loadRelaxed()->
thread.loadAcquire() ==
mainThread()
1316 && QCoreApplication::self
1317 && QCoreApplication::self->d_func()->sendThroughApplicationEventFilters(receiver,
event)) {
1322 if (sendThroughObjectEventFilters(receiver,
event)) {
1389 if (!
data->hasEventDispatcher())
1391 data->eventDispatcher.loadRelaxed()->processEvents(
flags);
1441 if (!
data->hasEventDispatcher())
1485 QThreadData *threadData = self->d_func()->threadData.loadAcquire();
1487 qWarning(
"%s::exec: Must be called from the main thread", self->metaObject()->className());
1491 qWarning(
"QCoreApplication::exec: The event loop is already running");
1497 self->d_func()->in_exec =
true;
1498 self->d_func()->aboutToQuitEmitted =
false;
1503 self->d_func()->execCleanup();
1516 threadData.loadRelaxed()->
quitNow =
false;
1519 qCDebug(lcDeleteLater) <<
"Sending deferred delete events as part of exec cleanup";
1559 if (!
d->aboutToQuitEmitted) {
1560 emit self->aboutToQuit(QCoreApplication::QPrivateSignal());
1561 d->aboutToQuitEmitted =
true;
1567 eventLoop->
exit(returnCode);
1575#ifndef QT_NO_QOBJECT
1592 Q_ASSERT_X(receiver,
"QCoreApplication::sendEvent",
"Unexpected null receiver");
1593 Q_ASSERT_X(
event,
"QCoreApplication::sendEvent",
"Unexpected null event");
1597 event->m_spont =
false;
1598 return notifyInternal2(receiver,
event);
1606 Q_ASSERT_X(receiver,
"QCoreApplication::sendSpontaneousEvent",
"Unexpected null receiver");
1607 Q_ASSERT_X(
event,
"QCoreApplication::sendSpontaneousEvent",
"Unexpected null event");
1611 event->m_spont =
true;
1612 return notifyInternal2(receiver,
event);
1632 locker.
threadData = threadData.loadAcquire();
1639 if (locker.
threadData == threadData.loadAcquire()) {
1640 locker.
locker = std::move(temporaryLocker);
1676 Q_ASSERT_X(
event,
"QCoreApplication::postEvent",
"Unexpected null event");
1681 if (receiver ==
nullptr) {
1682 qWarning(
"QCoreApplication::postEvent: Unexpected null receiver");
1688 if (!locker.threadData) {
1697 if (receiver->d_func()->postedEvents
1698 && self && self->compressEvent(
event, receiver, &
data->postEventList)) {
1699 Q_TRACE(QCoreApplication_postEvent_event_compressed, receiver,
event);
1705 std::unique_ptr<QEvent> eventDeleter(
event);
1706 Q_TRACE(QCoreApplication_postEvent_event_posted, receiver,
event,
event->type());
1709 event->m_posted =
true;
1710 ++receiver->d_func()->postedEvents;
1711 data->canWait =
false;
1729 int receiverPostedEvents = receiver->d_func()->postedEvents.loadRelaxed();
1733 auto sameReceiver = [receiver](
const QPostEvent &e) {
return e.receiver == receiver; };
1734 auto it = std::find_if(postedEvents->
cbegin(), postedEvents->
cend(), sameReceiver);
1735 while (receiverPostedEvents > 0 &&
it != postedEvents->
cend()) {
1742 if (--receiverPostedEvents)
1743 it = std::find_if(
it + 1, postedEvents->
cend(), sameReceiver);
1749 for (
const QPostEvent &cur : std::as_const(*postedEvents)) {
1750 if (cur.receiver != receiver
1751 || cur.
event ==
nullptr
1752 || cur.event->type() !=
event->type())
1793 if (event_type == -1) {
1798 if (receiver && receiver->d_func()->threadData.loadRelaxed() !=
data) {
1799 qWarning(
"QCoreApplication::sendPostedEvents: Cannot send "
1800 "posted events for objects in another thread");
1804 ++
data->postEventList.recursion;
1806 auto locker = qt_unique_lock(
data->postEventList.mutex);
1811 data->canWait = (
data->postEventList.size() == 0);
1813 if (
data->postEventList.size() == 0 || (receiver && !receiver->d_func()->postedEvents)) {
1814 --
data->postEventList.recursion;
1818 data->canWait =
true;
1823 qsizetype &
i = (!event_type && !receiver) ?
data->postEventList.startOffset : startOffset;
1824 data->postEventList.insertionOffset =
data->postEventList.size();
1831 bool exceptionCaught;
1834 receiver(receiver), event_type(event_type),
data(
data), exceptionCaught(
true)
1838 if (exceptionCaught) {
1840 data->canWait =
false;
1843 --
data->postEventList.recursion;
1844 if (!
data->postEventList.recursion && !
data->canWait &&
data->hasEventDispatcher())
1845 data->eventDispatcher.loadRelaxed()->wakeUp();
1849 if (!event_type && !receiver &&
data->postEventList.startOffset >= 0) {
1850 const QPostEventList::iterator
it =
data->postEventList.
begin();
1851 data->postEventList.erase(
it,
it +
data->postEventList.startOffset);
1852 data->postEventList.insertionOffset -=
data->postEventList.startOffset;
1854 data->postEventList.startOffset = 0;
1858 CleanUp cleanup(receiver, event_type,
data);
1860 while (i < data->postEventList.size()) {
1862 if (
i >=
data->postEventList.insertionOffset)
1870 if ((receiver && receiver != pe.receiver) || (event_type && event_type != pe.event->type())) {
1871 data->canWait =
false;
1883 qCDebug(lcDeleteLater) <<
"Processing deferred delete event for" << pe.receiver
1884 <<
"with loop level" <<
event->loopLevel() <<
"and scope level" <<
event->scopeLevel();
1886 qCDebug(lcDeleteLater) <<
"Checking" <<
data->thread <<
"with loop level"
1887 <<
data->loopLevel <<
"and scope level" <<
data->scopeLevel;
1889 bool allowDeferredDelete =
false;
1890 if (
event->loopLevel() == 0 &&
data->loopLevel > 0) {
1891 qCDebug(lcDeleteLater) <<
"Event was posted outside outermost event loop"
1892 <<
"and current thread has an event loop running.";
1893 allowDeferredDelete =
true;
1895 const int totalEventLevel =
event->loopLevel() +
event->scopeLevel();
1896 const int totalThreadLevel =
data->loopLevel +
data->scopeLevel;
1898 if (totalEventLevel > totalThreadLevel) {
1899 qCDebug(lcDeleteLater) <<
"Combined levels of event" << totalEventLevel
1900 <<
"is higher than thread" << totalThreadLevel;
1901 allowDeferredDelete =
true;
1903 qCDebug(lcDeleteLater) <<
"Explicit send of DeferredDelete and"
1904 <<
"levels of event" << totalEventLevel
1905 <<
"is same as thread" << totalThreadLevel;
1906 allowDeferredDelete =
true;
1910 if (!allowDeferredDelete) {
1911 qCDebug(lcDeleteLater) <<
"Failed conditions for deferred delete. Deferring again";
1914 if (!event_type && !receiver) {
1926 data->postEventList.addEvent(pe_copy);
1930 qCDebug(lcDeleteLater) <<
"Sending deferred delete to" << pe.receiver;
1936 pe.event->m_posted =
false;
1940 --
r->d_func()->postedEvents;
1941 Q_ASSERT(
r->d_func()->postedEvents >= 0);
1948 const auto relocker =
qScopeGuard([&locker] { locker.lock(); });
1950 QScopedPointer<QEvent> event_deleter(e);
1960 cleanup.exceptionCaught =
false;
1991 if (receiver && !receiver->d_func()->postedEvents)
1996 QVarLengthArray<QEvent*> events;
2003 if ((!receiver || pe.receiver == receiver)
2004 && (pe.event && (eventType == 0 || pe.event->type() == eventType))) {
2005 --pe.
receiver->d_func()->postedEvents;
2006 pe.
event->m_posted =
false;
2007 events.append(pe.event);
2009 }
else if (!
data->postEventList.recursion) {
2017 if (receiver && eventType == 0) {
2018 Q_ASSERT(!receiver->d_func()->postedEvents);
2022 if (!
data->postEventList.recursion) {
2024 data->postEventList.erase(
data->postEventList.begin() +
j,
data->postEventList.end());
2048 const auto locker = qt_scoped_lock(
data->postEventList.mutex);
2050 if (
data->postEventList.size() == 0) {
2051#if defined(QT_DEBUG)
2052 qDebug(
"QCoreApplication::removePostedEvent: Internal error: %p %d is posted",
2058 for (
const QPostEvent &pe : std::as_const(
data->postEventList)) {
2059 if (pe.event ==
event) {
2061 qWarning(
"QCoreApplication::removePostedEvent: Event of type %d deleted while posted to %s %s",
2063 pe.receiver->metaObject()->className(),
2064 pe.receiver->objectName().toLocal8Bit().data());
2066 --pe.receiver->d_func()->postedEvents;
2067 pe.event->m_posted =
false;
2094 quitLockRef.deref();
2097 quitAutomatically();
2111 if (quitLockRef.loadRelaxed())
2169 if (!self->d_func()->in_exec)
2172 self->d_func()->quit();
2210#ifndef QT_NO_TRANSLATION
2241 if (!translationFile)
2249 d->translators.prepend(translationFile);
2252#ifndef QT_NO_TRANSLATION_BUILDER
2253 if (translationFile->isEmpty())
2257#ifndef QT_NO_QOBJECT
2277 if (!translationFile)
2283 if (
d->translators.removeAll(translationFile)) {
2284#ifndef QT_NO_QOBJECT
2286 if (!self->closingDown()) {
2301 while ((percentPos =
result->indexOf(u
'%', percentPos +
len)) != -1) {
2306 if (
result->at(percentPos +
len) == u
'L') {
2314 if (
result->at(percentPos +
len) == u
'n') {
2358 const char *disambiguation,
int n)
2368 if (!
d->translators.isEmpty()) {
2372 translationFile = *
it;
2373 result = translationFile->translate(
context, sourceText, disambiguation,
n);
2395 if (!QCoreApplication::self)
2399 return d->translators.contains(translator);
2405 const char *disambiguation,
int n)
2453 qWarning(
"QCoreApplication::applicationDirPath: Please instantiate the QApplication object first");
2458 if (
d->cachedApplicationDirPath.isNull())
2460 return d->cachedApplicationDirPath;
2463#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN)
2466# if defined(Q_OS_ANDROID)
2469# elif defined(Q_OS_LINUX)
2472# elif defined(AT_EXECPATH)
2475 if (elf_aux_info(AT_EXECPATH, execfn,
sizeof(execfn)) != 0)
2505 qWarning(
"QCoreApplication::applicationFilePath: Please instantiate the QApplication object first");
2516 procName.assign(
d->argv[0]);
2524 if (absPath.isEmpty() && !
arguments().isEmpty()) {
2527 if (!argv0.isEmpty() && argv0.at(0) == u
'/') {
2533 }
else if (argv0.contains(u
'/')) {
2549 if (!absPath.isEmpty()) {
2563#if defined(Q_OS_WIN)
2564 return GetCurrentProcessId();
2565#elif defined(Q_OS_VXWORKS)
2566 return (pid_t) taskIdCurrent;
2608 qWarning(
"QCoreApplication::arguments: Please instantiate the QApplication object first");
2614 const int argc =
d->argc;
2615 char **
const argv =
d->argv;
2618#if defined(Q_OS_WIN)
2619 const bool argsModifiedByUser =
d->origArgv ==
nullptr;
2620 if (!argsModifiedByUser) {
2627 QStringList commandLineArguments = qWinCmdArgs(cmdline);
2632 if (argc !=
d->origArgc) {
2639 for (
int i = 0;
i <
d->origArgc; ++
i) {
2645 return commandLineArguments;
2649 for (
int a = 0;
a < argc; ++
a)
2681 if (coreappdata()->orgName == orgName)
2683 coreappdata()->orgName = orgName;
2684#ifndef QT_NO_QOBJECT
2685 if (QCoreApplication::self)
2686 emit QCoreApplication::self->organizationNameChanged();
2692 return coreappdata()->orgName;
2718 if (coreappdata()->orgDomain == orgDomain)
2720 coreappdata()->orgDomain = orgDomain;
2721#ifndef QT_NO_QOBJECT
2722 if (QCoreApplication::self)
2723 emit QCoreApplication::self->organizationDomainChanged();
2729 return coreappdata()->orgDomain;
2756 coreappdata()->applicationNameSet = !application.
isEmpty();
2757 QString newAppName = application;
2758 if (newAppName.isEmpty() && QCoreApplication::self)
2759 newAppName = QCoreApplication::self->d_func()->appName();
2760 if (coreappdata()->application == newAppName)
2762 coreappdata()->application = newAppName;
2763#ifndef QT_NO_QOBJECT
2764 if (QCoreApplication::self)
2765 emit QCoreApplication::self->applicationNameChanged();
2771 return coreappdata() ? coreappdata()->application :
QString();
2809 coreappdata()->applicationVersionSet = !version.
isEmpty();
2811 if (newVersion.isEmpty() && QCoreApplication::self)
2812 newVersion = QCoreApplication::self->d_func()->appVersion();
2815 coreappdata()->applicationVersion = newVersion;
2816#ifndef QT_NO_QOBJECT
2817 if (QCoreApplication::self)
2818 emit QCoreApplication::self->applicationVersionChanged();
2824 return coreappdata() ? coreappdata()->applicationVersion :
QString();
2827#if QT_CONFIG(permissions) || defined(Q_QDOC)
2917void QCoreApplication::requestPermission(
const QPermission &requestedPermission,
2924 qWarning(lcPermissions,
"Permissions can only be requested from the GUI (main) thread");
2928 class PermissionReceiver :
public QObject
2938 void finalizePermissionRequest(
const QPermission &permission)
2951 QPointer<const QObject>
context;
2954 PermissionReceiver *receiver =
new PermissionReceiver(std::move(slotObj),
context);
2959 "Internal error: requestPermission() should never return Undetermined");
2963 if (QCoreApplication::self) {
2965 permission.m_status = status;
2967 &PermissionReceiver::finalizePermissionRequest,
2976#if QT_CONFIG(library)
3012 return libraryPathsLocked();
3020 if (coreappdata()->manual_libpaths)
3021 return *(coreappdata()->manual_libpaths);
3023 if (!coreappdata()->app_libpaths) {
3025 coreappdata()->app_libpaths.reset(app_libpaths);
3027 auto setPathsFromEnv = [&](
QString libPathEnv) {
3028 if (!libPathEnv.isEmpty()) {
3045 if (CFBundleRef bundleRef = CFBundleGetMainBundle()) {
3046 if (QCFType<CFURLRef> urlRef = CFBundleCopyBuiltInPlugInsURL(bundleRef)) {
3047 if (QCFType<CFURLRef> absoluteUrlRef = CFURLCopyAbsoluteURL(urlRef)) {
3048 if (
QCFString path = CFURLCopyFileSystemPath(absoluteUrlRef, kCFURLPOSIXPathStyle)) {
3051 if (!app_libpaths->contains(
path))
3064 if (!app_libpaths->contains(installPathPlugins))
3065 app_libpaths->
append(installPathPlugins);
3070 if (self) self->d_func()->appendApplicationPathToLibraryPaths();
3072 return *(coreappdata()->app_libpaths);
3096 if (!coreappdata()->app_libpaths)
3097 libraryPathsLocked();
3099 if (coreappdata()->manual_libpaths)
3100 *(coreappdata()->manual_libpaths) =
paths;
3105 QFactoryLoader::refreshAll();
3124void QCoreApplication::addLibraryPath(
const QString &
path)
3135 QStringList *libpaths = coreappdata()->manual_libpaths.get();
3141 libraryPathsLocked();
3142 QStringList *app_libpaths = coreappdata()->app_libpaths.get();
3146 coreappdata()->manual_libpaths.reset(libpaths =
new QStringList(*app_libpaths));
3151 QFactoryLoader::refreshAll();
3163void QCoreApplication::removeLibraryPath(
const QString &
path)
3174 QStringList *libpaths = coreappdata()->manual_libpaths.get();
3180 libraryPathsLocked();
3181 QStringList *app_libpaths = coreappdata()->app_libpaths.get();
3185 coreappdata()->manual_libpaths.reset(libpaths =
new QStringList(*app_libpaths));
3190 QFactoryLoader::refreshAll();
3195#ifndef QT_NO_QOBJECT
3229 qWarning(
"Native event filters are not applied when the Qt::AA_PluginApplication attribute is set");
3404#ifndef QT_NO_QOBJECT
3405#include "moc_qcoreapplication.cpp"
static QAbstractEventDispatcher * instance(QThread *thread=nullptr)
Returns a pointer to the event dispatcher object for the specified thread.
virtual void wakeUp()=0
\threadsafe
Type loadRelaxed() const noexcept
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
static bool checkInstance(const char *method)
static bool isTranslatorInstalled(QTranslator *translator)
QString appVersion() const
void appendApplicationPathToLibraryPaths(void)
static QPostEventListLocker lockThreadPostEventList(QObject *object)
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
static bool is_app_closing
~QCoreApplicationPrivate()
QCoreApplicationPrivate(int &aargc, char **aargv)
bool sendThroughApplicationEventFilters(QObject *, QEvent *)
void processCommandLineArguments()
static QString * cachedApplicationFilePath
virtual void eventDispatcherReady()
static bool sendThroughObjectEventFilters(QObject *, QEvent *)
static bool is_app_running
static void checkReceiverThread(QObject *receiver)
static QAbstractEventDispatcher * eventDispatcher
static bool testAttribute(uint flag)
virtual void createEventDispatcher()
static void clearApplicationFilePath()
static bool setuidAllowed
static QBasicAtomicPointer< void > theMainThreadId
static QThread * mainThread()
static void removePostedEvent(QEvent *)
Removes event from the queue of posted events, and emits a warning message if appropriate.
virtual bool canQuitAutomatically()
static void setApplicationFilePath(const QString &path)
static bool threadRequiresCoreApplication()
static QBasicAtomicPointer< QThread > theMainThread
static bool notify_helper(QObject *, QEvent *)
QString qmljs_debug_arguments
void * resolveInterface(const char *name, int revision) const
\macro Q_DECLARE_TR_FUNCTIONS(context)
static QAbstractEventDispatcher * eventDispatcher()
Returns a pointer to the event dispatcher object for the main thread.
static QString applicationFilePath()
Returns the file path of the application executable.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool isSetuidAllowed()
bool event(QEvent *) override
\reimp
static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
Sets the event dispatcher for the main thread to eventDispatcher.
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *)
void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj)
Removes an event filterObject from this object.
static void quit()
\threadsafe
virtual bool notify(QObject *, QEvent *)
Sends event to receiver: {receiver}->event(event).
static void removePostedEvents(QObject *receiver, int eventType=0)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
static void setOrganizationDomain(const QString &orgDomain)
static bool isQuitLockEnabled()
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
QString applicationVersion
the version of this application
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
Installs an event filter filterObj for all native events received by the application in the main thre...
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
QString organizationName
the name of the organization that wrote this application
static void setOrganizationName(const QString &orgName)
[11]
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static QString applicationDirPath()
Returns the directory that contains the application executable.
static void setApplicationName(const QString &application)
static int exec()
Enters the main event loop and waits until exit() is called.
static bool installTranslator(QTranslator *messageFile)
Adds the translation file translationFile to the list of translation files to be used for translation...
static bool startingUp()
Returns true if an application object has not been created yet; otherwise returns false.
static qint64 applicationPid() Q_DECL_CONST_FUNCTION
static void setApplicationVersion(const QString &version)
static bool removeTranslator(QTranslator *messageFile)
Removes the translation file translationFile from the list of translation files used by this applicat...
static QStringList arguments()
static void setQuitLockEnabled(bool enabled)
~QCoreApplication()
Destroys the QCoreApplication object.
QString applicationName
the name of this application
static void setSetuidAllowed(bool allow)
static void sendPostedEvents(QObject *receiver=nullptr, int event_type=0)
Immediately dispatches all events which have been previously queued with QCoreApplication::postEvent(...
static void exit(int retcode=0)
Tells the application to exit with a return code.
bool quitLockEnabled
Whether the use of the QEventLoopLocker feature can cause the application to quit.
QString organizationDomain
the Internet domain of the organization that wrote this application
bool hasExpired() const noexcept
Returns true if this QDeadlineTimer object has expired, false if there remains time left.
static QDir current()
Returns the application's current directory.
QString canonicalPath() const
Returns the canonical path, i.e.
static constexpr QChar listSeparator() noexcept
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
Type
This enum type defines the valid event types in Qt.
Type type() const
Returns the event type.
QString canonicalFilePath() const
Returns the file system entry's canonical path, including the entry's name, that is,...
QString path() const
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name.
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static bool activateCallbacks(Callback, void **)
static QString path(LibraryPath p)
qsizetype size() const noexcept
bool isEmpty() const noexcept
qsizetype removeAll(const AT &t)
void prepend(rvalue_ref t)
void reserve(qsizetype size)
const_iterator cend() const noexcept
const_iterator cbegin() const noexcept
static QLoggingRegistry * instance()
static QObjectPrivate * get(QObject *o)
QAtomicPointer< QThreadData > threadData
QString objectName
the name of this object
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
friend class QCoreApplication
QThread * thread() const
Returns the thread in which the object lives.
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
\inmodule QtCore \inheaderfile QPermissions
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
static QString findExecutable(const QString &executableName, const QStringList &paths=QStringList())
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & append(QChar c)
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
static Q_AUTOTEST_EXPORT QThreadData * current(bool createIfNecessary=true)
QStack< QEventLoop * > eventLoops
static QThreadData * get2(QThread *thread)
QPostEventList postEventList
QAtomicPointer< QThread > thread
static QThreadPool * qtGuiInstance()
Returns the QThreadPool instance for Qt Gui.
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
static QThread * currentThread()
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
void(* StartupCallback)()
void requestPermission(const QPermission &permission, const PermissionCallback &callback)
Qt::PermissionStatus checkPermission(const QPermission &permission)
Combined button and popup list for selecting options.
void initBindingStatusThreadId()
std::unique_ptr< QSlotObjectBase, QSlotObjectBase::Deleter > SlotObjUniquePtr
@ AA_SynthesizeMouseForUnhandledTabletEvents
@ AA_SynthesizeMouseForUnhandledTouchEvents
#define Q_BASIC_ATOMIC_INITIALIZER(a)
static QThread * mainThread
size_t qstrlen(const char *str)
Q_CORE_EXPORT int qstricmp(const char *, const char *)
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N)
#define Q_DECL_EXPORT_OVERRIDABLE
QList< QString > QStringList
Constructs a string list that contains the given string, str.
QByteArray qt_readlink(const char *path)
QList< QtCleanUpFunction > QVFuncList
void qAddPreRoutine(QtStartUpFunction p)
static Q_CONSTINIT bool preRoutinesCalled
static Q_CONSTINIT bool quitLockEnabled
static QString qAppFileName()
void qAddPostRoutine(QtCleanUpFunction p)
static void qt_call_pre_routines()
qsizetype qGlobalPostedEventsCount()
static Q_CONSTINIT QBasicMutex globalRoutinesMutex
static bool doNotify(QObject *, QEvent *)
QList< QtStartUpFunction > QStartUpFuncList
static void replacePercentN(QString *result, int n)
void Q_CORE_EXPORT qt_call_post_routines()
void qRemovePostRoutine(QtCleanUpFunction p)
void(* QtCleanUpFunction)()
void(* QtStartUpFunction)()
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint attribute
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
QT_BEGIN_NAMESPACE quintptr Q_CORE_EXPORT qtHookData[]
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei const GLuint * paths
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
static qreal dot(const QPointF &a, const QPointF &b)
#define Q_ASSERT_X(cond, x, msg)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
static QString canonicalPath(const QString &rootPath)
#define qUtf16Printable(string)
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
#define QStringLiteral(str)
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
#define Q_TRACE_METADATA(provider, metadata)
#define Q_TRACE_PREFIX(provider, prefix)
#define Q_TRACE_SCOPE(x,...)
#define Q_TRACE_INSTRUMENT(provider)
#define Q_TRACE_EXIT(x,...)
#define Q_TRACE_POINT(provider, tracepoint,...)
Q_CORE_EXPORT QString qtTrId(const char *id, int n=-1)
QVideoFrameFormat::PixelFormat fmt
if(qFloatDistance(a, b)<(1<< 7))
[0]
QTextStream out(stdout)
[7]
QDeadlineTimer deadline(30s)
myObject moveToThread(QApplication::instance() ->thread())
[6]
QString applicationVersion
QCoreApplicationData() noexcept
bool applicationVersionSet
std::unique_lock< QMutex > locker