summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorJani Heikkinen <jani.heikkinen@qt.io>2018-02-10 20:39:02 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2018-02-10 20:39:02 +0000
commit095dbc494c6cb9815b0d9b521a3105b06f4bef33 (patch)
treeec5b2ac5777406a533e820f21b5705b209855a0d /src/corelib/kernel
parent0b48fcee709ac0070d7b9213632edeafeeddc9e1 (diff)
parent32b506d1db1f8cee748a27b548ba8208f2928058 (diff)
Merge "Merge remote-tracking branch 'origin/dev' into 5.11" into refs/staging/5.11
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp10
-rw-r--r--src/corelib/kernel/qeventdispatcher_cf.mm87
-rw-r--r--src/corelib/kernel/qeventdispatcher_cf_p.h20
-rw-r--r--src/corelib/kernel/qvariant.cpp13
-rw-r--r--src/corelib/kernel/qvariant.h19
5 files changed, 86 insertions, 63 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index e93a14c116..4bab0b9f01 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -116,6 +116,12 @@
# include <taskLib.h>
#endif
+#ifdef QT_BOOTSTRAPPED
+#include <private/qtrace_p.h>
+#else
+#include <qtcore_tracepoints_p.h>
+#endif
+
#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -790,6 +796,8 @@ QCoreApplication::QCoreApplication(int &argc, char **argv
void QCoreApplicationPrivate::init()
{
+ Q_TRACE(qcoreapplicationprivate_init_entry);
+
#if defined(Q_OS_MACOS)
QMacAutoReleasePool pool;
#endif
@@ -873,6 +881,8 @@ void QCoreApplicationPrivate::init()
#ifndef QT_NO_QOBJECT
is_app_running = true; // No longer starting up.
#endif
+
+ Q_TRACE(qcoreapplicationprivate_init_exit);
}
/*!
diff --git a/src/corelib/kernel/qeventdispatcher_cf.mm b/src/corelib/kernel/qeventdispatcher_cf.mm
index 608dea5426..8499b3fd57 100644
--- a/src/corelib/kernel/qeventdispatcher_cf.mm
+++ b/src/corelib/kernel/qeventdispatcher_cf.mm
@@ -112,14 +112,15 @@ static CFStringRef runLoopMode(NSDictionary *dictionary)
if (CFStringRef mode = runLoopMode(notification.userInfo))
m_runLoopModes.push(mode);
else
- qWarning("Encountered run loop push notification without run loop mode!");
+ qCWarning(lcEventDispatcher) << "Encountered run loop push notification without run loop mode!";
} else if (CFStringHasSuffix((CFStringRef)notification.name, CFSTR("RunLoopModePopNotification"))) {
CFStringRef mode = runLoopMode(notification.userInfo);
if (CFStringCompare(mode, [self currentMode], 0) == kCFCompareEqualTo)
m_runLoopModes.pop();
else
- qWarning("Tried to pop run loop mode '%s' that was never pushed!", qPrintable(QString::fromCFString(mode)));
+ qCWarning(lcEventDispatcher) << "Tried to pop run loop mode"
+ << qPrintable(QString::fromCFString(mode)) << "that was never pushed!";
Q_ASSERT(m_runLoopModes.size() >= 1);
}
@@ -134,6 +135,9 @@ static CFStringRef runLoopMode(NSDictionary *dictionary)
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher");
+Q_LOGGING_CATEGORY(lcEventDispatcherTimers, "qt.eventdispatcher.timers");
+
class RunLoopDebugger : public QObject
{
Q_OBJECT
@@ -177,10 +181,6 @@ QDebug operator<<(QDebug s, timespec tv)
return s;
}
-#if DEBUG_EVENT_DISPATCHER
-uint g_eventDispatcherIndentationLevel = 0;
-#endif
-
static const CFTimeInterval kCFTimeIntervalMinimum = 0;
static const CFTimeInterval kCFTimeIntervalDistantFuture = std::numeric_limits<CFTimeInterval>::max();
@@ -190,13 +190,7 @@ QEventDispatcherCoreFoundation::QEventDispatcherCoreFoundation(QObject *parent)
: QAbstractEventDispatcher(parent)
, m_processEvents(QEventLoop::EventLoopExec)
, m_postedEventsRunLoopSource(this, &QEventDispatcherCoreFoundation::processPostedEvents)
- , m_runLoopActivityObserver(this, &QEventDispatcherCoreFoundation::handleRunLoopActivity,
-#if DEBUG_EVENT_DISPATCHER
- kCFRunLoopAllActivities
-#else
- kCFRunLoopBeforeWaiting | kCFRunLoopAfterWaiting
-#endif
- )
+ , m_runLoopActivityObserver(this, &QEventDispatcherCoreFoundation::handleRunLoopActivity, kCFRunLoopAllActivities)
, m_runLoopModeTracker([[RunLoopModeTracker alloc] init])
, m_runLoopTimer(0)
, m_blockedRunLoopTimer(0)
@@ -247,14 +241,14 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
bool eventsProcessed = false;
if (flags & (QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers))
- qWarning() << "processEvents() flags" << flags << "not supported on iOS";
+ qCWarning(lcEventDispatcher) << "processEvents() flags" << flags << "not supported on iOS";
- qEventDispatcherDebug() << "Entering with " << flags; qIndent();
+ qCDebug(lcEventDispatcher) << "Processing events with flags" << flags;
if (m_blockedRunLoopTimer) {
Q_ASSERT(m_blockedRunLoopTimer == m_runLoopTimer);
- qEventDispatcherDebug() << "Recursing from blocked timer " << m_blockedRunLoopTimer;
+ qCDebug(lcEventDispatcher) << "Recursing from blocked timer" << m_blockedRunLoopTimer;
m_runLoopTimer = 0; // Unset current timer to force creation of new timer
updateTimers();
}
@@ -266,7 +260,7 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
m_postedEventsRunLoopSource.signal();
m_processEvents.deferredWakeUp = false;
- qEventDispatcherDebug() << "Processed deferred wake-up";
+ qCDebug(lcEventDispatcher) << "Processed deferred wake-up";
}
// The documentation states that this signal is emitted after the event
@@ -287,12 +281,12 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
CFTimeInterval duration = (m_processEvents.flags & QEventLoop::WaitForMoreEvents) ?
kCFTimeIntervalDistantFuture : kCFTimeIntervalMinimum;
- qEventDispatcherDebug() << "Calling CFRunLoopRunInMode = " << qPrintable(QString::fromCFString(mode))
- << " for " << duration << " ms, processing single source = " << returnAfterSingleSourceHandled; qIndent();
+ qCDebug(lcEventDispatcher) << "Calling CFRunLoopRunInMode =" << qPrintable(QString::fromCFString(mode))
+ << "for" << duration << "ms, processing single source =" << returnAfterSingleSourceHandled;
SInt32 result = CFRunLoopRunInMode(mode, duration, returnAfterSingleSourceHandled);
- qUnIndent(); qEventDispatcherDebug() << "result = " << qPrintableResult(result);
+ qCDebug(lcEventDispatcher) << "result =" << qPrintableResult(result);
eventsProcessed |= (result == kCFRunLoopRunHandledSource
|| m_processEvents.processedPostedEvents
@@ -316,15 +310,15 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
// immediately, since it has already been exited.
if (!currentEventLoop()->isRunning()) {
- qEventDispatcherDebug() << "Top level event loop was exited";
+ qCDebug(lcEventDispatcher) << "Top level event loop was exited";
break;
} else {
- qEventDispatcherDebug() << "Top level event loop still running, making another pass";
+ qCDebug(lcEventDispatcher) << "Top level event loop still running, making another pass";
}
} else {
// We were called manually, through processEvents(), and should stop processing
// events, even if we didn't finish processing all the queued events.
- qEventDispatcherDebug() << "Top level processEvents was interrupted";
+ qCDebug(lcEventDispatcher) << "Top level processEvents was interrupted";
break;
}
}
@@ -353,7 +347,7 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
// date in the past (overdue) will fire on the next run loop pass. The Qt
// APIs on the other hand document eg. zero-interval timers to always be
// handled after processing all available window-system events.
- qEventDispatcherDebug() << "Manually processing timers due to overdue timer";
+ qCDebug(lcEventDispatcher) << "Manually processing timers due to overdue timer";
processTimers(0);
eventsProcessed = true;
}
@@ -372,7 +366,7 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
if (m_processEvents.deferredWakeUp) {
m_postedEventsRunLoopSource.signal();
- qEventDispatcherDebug() << "Processed deferred wake-up";
+ qCDebug(lcEventDispatcher) << "Processed deferred wake-up";
}
bool wasInterrupted = m_processEvents.wasInterrupted;
@@ -385,11 +379,11 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
// others below it (eg, in the case of nested event loops). We need to trigger
// another interrupt so that the parent processEvents call has a chance to check
// if it should continue.
- qEventDispatcherDebug() << "Forwarding interrupt in case of nested processEvents";
+ qCDebug(lcEventDispatcher) << "Forwarding interrupt in case of nested processEvents";
interrupt();
}
- qEventDispatcherDebug() << "Returning with eventsProcessed = " << eventsProcessed; qUnIndent();
+ qCDebug(lcEventDispatcher) << "Returning with eventsProcessed =" << eventsProcessed;
return eventsProcessed;
}
@@ -397,15 +391,14 @@ bool QEventDispatcherCoreFoundation::processEvents(QEventLoop::ProcessEventsFlag
bool QEventDispatcherCoreFoundation::processPostedEvents()
{
if (m_processEvents.processedPostedEvents && !(m_processEvents.flags & QEventLoop::EventLoopExec)) {
- qEventDispatcherDebug() << "Already processed events this pass";
+ qCDebug(lcEventDispatcher) << "Already processed events this pass";
return false;
}
m_processEvents.processedPostedEvents = true;
- qEventDispatcherDebug() << "Sending posted events for " << m_processEvents.flags; qIndent();
+ qCDebug(lcEventDispatcher) << "Sending posted events for" << m_processEvents.flags;
QCoreApplication::sendPostedEvents();
- qUnIndent();
return true;
}
@@ -413,12 +406,12 @@ bool QEventDispatcherCoreFoundation::processPostedEvents()
void QEventDispatcherCoreFoundation::processTimers(CFRunLoopTimerRef timer)
{
if (m_processEvents.processedTimers && !(m_processEvents.flags & QEventLoop::EventLoopExec)) {
- qEventDispatcherDebug() << "Already processed timers this pass";
+ qCDebug(lcEventDispatcher) << "Already processed timers this pass";
m_processEvents.deferredUpdateTimers = true;
return;
}
- qEventDispatcherDebug() << "CFRunLoopTimer " << timer << " fired, activating Qt timers"; qIndent();
+ qCDebug(lcEventDispatcher) << "CFRunLoopTimer" << timer << "fired, activating Qt timers";
// Activating Qt timers might recurse into processEvents() if a timer-callback
// brings up a new event-loop or tries to processes events manually. Although
@@ -436,15 +429,15 @@ void QEventDispatcherCoreFoundation::processTimers(CFRunLoopTimerRef timer)
m_blockedRunLoopTimer = previouslyBlockedRunLoopTimer;
m_processEvents.processedTimers = true;
- qUnIndent();
-
// Now that the timer source is unblocked we may need to schedule it again
updateTimers();
}
+Q_LOGGING_CATEGORY(lcEventDispatcherActivity, "qt.eventdispatcher.activity")
+
void QEventDispatcherCoreFoundation::handleRunLoopActivity(CFRunLoopActivity activity)
{
- qEventDispatcherDebug() << qPrintableActivity(activity);
+ qCDebug(lcEventDispatcherActivity) << "Runloop entered activity" << qPrintableActivity(activity);
switch (activity) {
case kCFRunLoopBeforeWaiting:
@@ -463,13 +456,11 @@ void QEventDispatcherCoreFoundation::handleRunLoopActivity(CFRunLoopActivity act
case kCFRunLoopAfterWaiting:
emit awake();
break;
-#if DEBUG_EVENT_DISPATCHER
case kCFRunLoopEntry:
case kCFRunLoopBeforeTimers:
case kCFRunLoopBeforeSources:
case kCFRunLoopExit:
break;
-#endif
default:
Q_UNREACHABLE();
}
@@ -502,19 +493,19 @@ void QEventDispatcherCoreFoundation::wakeUp()
// posted event gets processed on the next processEvents() call, so we flag the
// need to do a deferred wake-up.
m_processEvents.deferredWakeUp = true;
- qEventDispatcherDebug() << "Already processed posted events, deferring wakeUp";
+ qCDebug(lcEventDispatcher) << "Already processed posted events, deferring wakeUp";
return;
}
m_postedEventsRunLoopSource.signal();
CFRunLoopWakeUp(CFRunLoopGetMain());
- qEventDispatcherDebug() << "Signaled posted event run-loop source";
+ qCDebug(lcEventDispatcher) << "Signaled posted event run-loop source";
}
void QEventDispatcherCoreFoundation::interrupt()
{
- qEventDispatcherDebug() << "Marking current processEvent as interrupted";
+ qCDebug(lcEventDispatcher) << "Marking current processEvent as interrupted";
m_processEvents.wasInterrupted = true;
CFRunLoopStop(CFRunLoopGetMain());
}
@@ -540,8 +531,8 @@ void QEventDispatcherCoreFoundation::unregisterSocketNotifier(QSocketNotifier *n
void QEventDispatcherCoreFoundation::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
- qEventDispatcherDebug() << "id = " << timerId << ", interval = " << interval
- << ", type = " << timerType << ", object = " << object;
+ qCDebug(lcEventDispatcherTimers) << "Registering timer with id =" << timerId << "interval =" << interval
+ << "type =" << timerType << "object =" << object;
Q_ASSERT(timerId > 0 && interval >= 0 && object);
Q_ASSERT(object->thread() == thread() && thread() == QThread::currentThread());
@@ -557,7 +548,7 @@ bool QEventDispatcherCoreFoundation::unregisterTimer(int timerId)
bool returnValue = m_timerInfoList.unregisterTimer(timerId);
- qEventDispatcherDebug() << "id = " << timerId << ", timers left: " << m_timerInfoList.size();
+ qCDebug(lcEventDispatcherTimers) << "Unegistered timer with id =" << timerId << "Timers left:" << m_timerInfoList.size();
updateTimers();
return returnValue;
@@ -569,7 +560,7 @@ bool QEventDispatcherCoreFoundation::unregisterTimers(QObject *object)
bool returnValue = m_timerInfoList.unregisterTimers(object);
- qEventDispatcherDebug() << "object = " << object << ", timers left: " << m_timerInfoList.size();
+ qCDebug(lcEventDispatcherTimers) << "Unegistered timers for object =" << object << "Timers left:" << m_timerInfoList.size();
updateTimers();
return returnValue;
@@ -612,16 +603,16 @@ void QEventDispatcherCoreFoundation::updateTimers()
});
CFRunLoopAddTimer(CFRunLoopGetMain(), m_runLoopTimer, kCFRunLoopCommonModes);
- qEventDispatcherDebug() << "Created new CFRunLoopTimer " << m_runLoopTimer;
+ qCDebug(lcEventDispatcherTimers) << "Created new CFRunLoopTimer" << m_runLoopTimer;
} else {
CFRunLoopTimerSetNextFireDate(m_runLoopTimer, timeToFire);
- qEventDispatcherDebug() << "Re-scheduled CFRunLoopTimer " << m_runLoopTimer;
+ qCDebug(lcEventDispatcherTimers) << "Re-scheduled CFRunLoopTimer" << m_runLoopTimer;
}
m_overdueTimerScheduled = !timespecToSeconds(tv);
- qEventDispatcherDebug() << "Next timeout in " << tv << " seconds";
+ qCDebug(lcEventDispatcherTimers) << "Next timeout in" << tv << "seconds";
} else {
// No Qt timers are registered, so make sure we're not running any CF timers
@@ -637,7 +628,7 @@ void QEventDispatcherCoreFoundation::invalidateTimer()
return;
CFRunLoopTimerInvalidate(m_runLoopTimer);
- qEventDispatcherDebug() << "Invalidated CFRunLoopTimer " << m_runLoopTimer;
+ qCDebug(lcEventDispatcherTimers) << "Invalidated CFRunLoopTimer" << m_runLoopTimer;
CFRelease(m_runLoopTimer);
m_runLoopTimer = 0;
diff --git a/src/corelib/kernel/qeventdispatcher_cf_p.h b/src/corelib/kernel/qeventdispatcher_cf_p.h
index 8a234ebc40..a607ab7a15 100644
--- a/src/corelib/kernel/qeventdispatcher_cf_p.h
+++ b/src/corelib/kernel/qeventdispatcher_cf_p.h
@@ -85,19 +85,22 @@
// We mean it.
//
-#define DEBUG_EVENT_DISPATCHER 0
-
#include <QtCore/qabstracteventdispatcher.h>
#include <QtCore/private/qtimerinfo_unix_p.h>
#include <QtCore/private/qcfsocketnotifier_p.h>
#include <QtCore/private/qcore_mac_p.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qloggingcategory.h>
+
#include <CoreFoundation/CoreFoundation.h>
Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(RunLoopModeTracker));
QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher);
+Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcherTimers)
+
class QEventDispatcherCoreFoundation;
template <class T = QEventDispatcherCoreFoundation>
@@ -269,17 +272,4 @@ private:
QT_END_NAMESPACE
-#if DEBUG_EVENT_DISPATCHER
-extern uint g_eventDispatcherIndentationLevel;
-#define qEventDispatcherDebug() qDebug().nospace() \
- << qPrintable(QString(QLatin1String("| ")).repeated(g_eventDispatcherIndentationLevel)) \
- << __FUNCTION__ << "(): "
-#define qIndent() ++g_eventDispatcherIndentationLevel
-#define qUnIndent() --g_eventDispatcherIndentationLevel
-#else
-#define qEventDispatcherDebug() QT_NO_QDEBUG_MACRO()
-#define qIndent()
-#define qUnIndent()
-#endif
-
#endif // QEVENTDISPATCHER_CF_P_H
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 6fcc6b8d30..7ccacd883f 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -3892,6 +3892,19 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
\sa setValue(), value()
*/
+/*! \fn static inline QVariant fromStdVariant(const std::variant<T, Types...> &value)
+ \since 5.11
+
+ Returns a QVariant with the type and value of the active variant of \a value. If
+ the active type is std::monostate a default QVariant is returned.
+
+ \note With this method you do not need to register the variant as a Qt metatype,
+ since the std::variant is resolved before being stored. The component types
+ should be registered however.
+
+ \sa fromValue()
+*/
+
/*!
\fn template<typename T> QVariant qVariantFromValue(const T &value)
\relates QVariant
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 29e67e9dd8..fe1ef1bdfc 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -53,6 +53,10 @@
#include <QtCore/qbytearraylist.h>
#endif
+#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
+#include <variant>
+#endif
+
QT_BEGIN_NAMESPACE
@@ -355,6 +359,16 @@ class Q_CORE_EXPORT QVariant
static inline QVariant fromValue(const T &value)
{ return qVariantFromValue(value); }
+#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
+ template<typename... Types>
+ static inline QVariant fromStdVariant(const std::variant<Types...> &value)
+ {
+ if (value.valueless_by_exception())
+ return QVariant();
+ return std::visit([](const auto &arg) { return fromValue(arg); }, value);
+ }
+#endif
+
template<typename T>
bool canConvert() const
{ return canConvert(qMetaTypeId<T>()); }
@@ -503,6 +517,11 @@ inline QVariant qVariantFromValue(const T &t)
template <>
inline QVariant qVariantFromValue(const QVariant &t) { return t; }
+#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L
+template <>
+inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); }
+#endif
+
template <typename T>
inline void qVariantSetValue(QVariant &v, const T &t)
{