summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-06-14 11:56:56 +0200
committerLiang Qi <liang.qi@qt.io>2019-06-14 13:45:18 +0200
commitb1a216649ec064412160638dd00195cd47c567aa (patch)
treea4134415a3849cfb857942e698514be9da18924f /src/corelib
parent2e20ae3c1b57169497f6f3904623be4f5e617e12 (diff)
parent1632786f00875d23c7d111cbb29dedaa35c1c8c2 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: qmake/generators/makefile.cpp qmake/generators/unix/unixmake2.cpp src/corelib/thread/qthread_unix.cpp tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp Change-Id: I1df0d4ba20685de7f9300bf07458c13376493408
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/Qt5CoreMacros.cmake5
-rw-r--r--src/corelib/animation/qabstractanimation.cpp2
-rw-r--r--src/corelib/animation/qanimationgroup.cpp25
-rw-r--r--src/corelib/animation/qanimationgroup_p.h2
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.cpp3
-rw-r--r--src/corelib/doc/src/cmake-macros.qdoc2
-rw-r--r--src/corelib/doc/src/dontdocument.qdoc41
-rw-r--r--src/corelib/global/qglobal.cpp7
-rw-r--r--src/corelib/global/qlibraryinfo.cpp35
-rw-r--r--src/corelib/global/qlibraryinfo.h1
-rw-r--r--src/corelib/io/qfileselector.cpp11
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm31
-rw-r--r--src/corelib/kernel/qcore_mac_p.h71
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp5
-rw-r--r--src/corelib/kernel/qobject.h3
-rw-r--r--src/corelib/kernel/qobjectdefs.h4
-rw-r--r--src/corelib/thread/qthread_p.h3
-rw-r--r--src/corelib/thread/qthread_unix.cpp10
-rw-r--r--src/corelib/time/qdatetime.cpp199
-rw-r--r--src/corelib/time/qtimezoneprivate_tz.cpp43
-rw-r--r--src/corelib/tools/qregexp.cpp2
21 files changed, 374 insertions, 131 deletions
diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake
index 78b99f5bfe..0f006fe1e3 100644
--- a/src/corelib/Qt5CoreMacros.cmake
+++ b/src/corelib/Qt5CoreMacros.cmake
@@ -296,6 +296,9 @@ endfunction()
# qt5_add_big_resources(outfiles inputfile ... )
function(QT5_ADD_BIG_RESOURCES outfiles )
+ if (CMAKE_VERSION VERSION_LESS 3.9)
+ message(FATAL_ERROR, "qt5_add_big_resources requires CMake 3.9 or newer")
+ endif()
set(options)
set(oneValueArgs)
@@ -326,6 +329,8 @@ function(QT5_ADD_BIG_RESOURCES outfiles )
set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOMOC OFF)
set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOUIC OFF)
add_dependencies(rcc_object_${outfilename} big_resources_${outfilename})
+ # The modification of TARGET_OBJECTS needs the following change in cmake
+ # https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
add_custom_command(OUTPUT ${outfile}
COMMAND ${Qt5Core_RCC_EXECUTABLE}
ARGS ${rcc_options} --name ${outfilename} --pass 2 --temp $<TARGET_OBJECTS:rcc_object_${outfilename}> --output ${outfile} ${infile}
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index 0be37b7dca..c879eb6d1a 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -1067,6 +1067,8 @@ QAbstractAnimation::~QAbstractAnimation()
if (oldState == QAbstractAnimation::Running)
QAnimationTimer::unregisterAnimation(this);
}
+ if (d->group)
+ d->group->removeAnimation(this);
}
/*!
diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp
index f47d99eb68..ed40817222 100644
--- a/src/corelib/animation/qanimationgroup.cpp
+++ b/src/corelib/animation/qanimationgroup.cpp
@@ -113,6 +113,11 @@ QAnimationGroup::QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent)
*/
QAnimationGroup::~QAnimationGroup()
{
+ Q_D(QAnimationGroup);
+ // We need to clear the animations now while we are still a valid QAnimationGroup.
+ // If we wait until ~QObject() the QAbstractAnimation's pointer back to us would
+ // point to a QObject, not a valid QAnimationGroup.
+ d->clear(true);
}
/*!
@@ -256,7 +261,7 @@ QAbstractAnimation *QAnimationGroup::takeAnimation(int index)
void QAnimationGroup::clear()
{
Q_D(QAnimationGroup);
- qDeleteAll(d->animations);
+ d->clear(false);
}
/*!
@@ -284,6 +289,24 @@ bool QAnimationGroup::event(QEvent *event)
return QAbstractAnimation::event(event);
}
+void QAnimationGroupPrivate::clear(bool onDestruction)
+{
+ const QList<QAbstractAnimation *> animationsCopy = animations; // taking a copy
+ animations.clear();
+ // Clearing backwards so the indices doesn't change while we remove animations.
+ for (int i = animationsCopy.count() - 1; i >= 0; --i) {
+ QAbstractAnimation *animation = animationsCopy.at(i);
+ animation->setParent(nullptr);
+ QAbstractAnimationPrivate::get(animation)->group = nullptr;
+ // If we are in ~QAnimationGroup() it is not safe to called the virtual
+ // animationRemoved method, which can still be a method in a
+ // QAnimationGroupPrivate derived class that assumes q_ptr is still
+ // a valid derived class of QAnimationGroup.
+ if (!onDestruction)
+ animationRemoved(i, animation);
+ delete animation;
+ }
+}
void QAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *)
{
diff --git a/src/corelib/animation/qanimationgroup_p.h b/src/corelib/animation/qanimationgroup_p.h
index 215734b656..4d1d690e69 100644
--- a/src/corelib/animation/qanimationgroup_p.h
+++ b/src/corelib/animation/qanimationgroup_p.h
@@ -73,6 +73,8 @@ public:
virtual void animationInsertedAt(int) { }
virtual void animationRemoved(int, QAbstractAnimation *);
+ void clear(bool onDestruction);
+
void disconnectUncontrolledAnimation(QAbstractAnimation *anim)
{
//0 for the signal here because we might be called from the animation destructor
diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp
index 150e74d7d6..66e346a2fe 100644
--- a/src/corelib/animation/qsequentialanimationgroup.cpp
+++ b/src/corelib/animation/qsequentialanimationgroup.cpp
@@ -532,7 +532,8 @@ void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnim
Q_Q(QSequentialAnimationGroup);
QAnimationGroupPrivate::animationRemoved(index, anim);
- Q_ASSERT(currentAnimation); // currentAnimation should always be set
+ if (!currentAnimation)
+ return;
if (actualDuration.size() > index)
actualDuration.removeAt(index);
diff --git a/src/corelib/doc/src/cmake-macros.qdoc b/src/corelib/doc/src/cmake-macros.qdoc
index 6140e8be44..7fb133020f 100644
--- a/src/corelib/doc/src/cmake-macros.qdoc
+++ b/src/corelib/doc/src/cmake-macros.qdoc
@@ -131,6 +131,8 @@ files (\c .o, \c .obj) files instead of C++ source code. This allows to
embed bigger resources, where compiling to C++ sources and then to
binaries would be too time consuming or memory intensive.
+Note that this macro is only available if using \c{CMake} 3.9 or later.
+
\section1 Arguments
You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
diff --git a/src/corelib/doc/src/dontdocument.qdoc b/src/corelib/doc/src/dontdocument.qdoc
new file mode 100644
index 0000000000..19ca7db299
--- /dev/null
+++ b/src/corelib/doc/src/dontdocument.qdoc
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \dontdocument (QMacAutoReleasePool QIncompatibleFlag QGenericAtomicOps QAtomicTraits
+ QAtomicOps QBasicAtomicInteger QBasicAtomicPointer QBasicMutex QInternal
+ QArgument QReturnArgument QArrayData QTypedArrayData QStaticByteArrayData
+ QByteRef QStaticStringData QListSpecialMethods QListData QScopedPointerDeleter
+ QScopedPointerArrayDeleter QScopedPointerPodDeleter QScopedPointerObjectDeleteLater
+ QMetaTypeId2 QObjectData QObjectUserData QMapNodeBase QMapNode QMapDataBase
+ QMapData QHashData QHashNode QArrayDataPointer QTextStreamManipulator
+ QContiguousCacheData QContiguousCacheTypedData QNoDebug QUrlTwoFlags
+ QCborValueRef qfloat16 QDeferredDeleteEvent QSpecialInteger QLittleEndianStorageType
+ QBigEndianStorageType QFactoryInterface QFutureWatcherBase QJsonValuePtr
+ QJsonValueRefPtr QLinkedListNode QAbstractConcatenable QStringBuilderCommon
+ QTextCodec::ConverterState QThreadStorageData)
+*/
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 897f92a4ea..990554a682 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1553,6 +1553,13 @@ bool qSharedBuild() noexcept
*/
/*!
+ \macro Q_OS_WASM
+ \relates <QtGlobal>
+
+ Defined on Web Assembly.
+*/
+
+/*!
\macro Q_CC_SYM
\relates <QtGlobal>
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index c3eb469767..e82939dcd9 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -432,7 +432,24 @@ void QLibraryInfo::reload()
{
QLibraryInfoPrivate::reload();
}
-#endif
+
+void QLibraryInfo::sysrootify(QString *path)
+{
+ if (!QVariant::fromValue(rawLocation(SysrootifyPrefixPath, FinalPaths)).toBool())
+ return;
+
+ const QString sysroot = rawLocation(SysrootPath, FinalPaths);
+ if (sysroot.isEmpty())
+ return;
+
+ if (path->length() > 2 && path->at(1) == QLatin1Char(':')
+ && (path->at(2) == QLatin1Char('/') || path->at(2) == QLatin1Char('\\'))) {
+ path->replace(0, 2, sysroot); // Strip out the drive on Windows targets
+ } else {
+ path->prepend(sysroot);
+ }
+}
+#endif // QT_BUILD_QMAKE
/*!
Returns the location specified by \a loc.
@@ -444,18 +461,8 @@ QLibraryInfo::location(LibraryLocation loc)
QString ret = rawLocation(loc, FinalPaths);
// Automatically prepend the sysroot to target paths
- if (loc < SysrootPath || loc > LastHostPath) {
- QString sysroot = rawLocation(SysrootPath, FinalPaths);
- if (!sysroot.isEmpty()
- && QVariant::fromValue(rawLocation(SysrootifyPrefixPath, FinalPaths)).toBool()) {
- if (ret.length() > 2 && ret.at(1) == QLatin1Char(':')
- && (ret.at(2) == QLatin1Char('/') || ret.at(2) == QLatin1Char('\\'))) {
- ret.replace(0, 2, sysroot); // Strip out the drive on Windows targets
- } else {
- ret.prepend(sysroot);
- }
- }
- }
+ if (loc < SysrootPath || loc > LastHostPath)
+ sysrootify(&ret);
return ret;
}
@@ -598,6 +605,8 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
} else {
// we make any other path absolute to the prefix directory
baseDir = rawLocation(PrefixPath, group);
+ if (group == EffectivePaths)
+ sysrootify(&baseDir);
}
#else
if (loc == PrefixPath) {
diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h
index 20fd3897f7..ed60b170a5 100644
--- a/src/corelib/global/qlibraryinfo.h
+++ b/src/corelib/global/qlibraryinfo.h
@@ -107,6 +107,7 @@ public:
enum PathGroup { FinalPaths, EffectivePaths, EffectiveSourcePaths, DevicePaths };
static QString rawLocation(LibraryLocation, PathGroup);
static void reload();
+ static void sysrootify(QString *path);
#endif
static QStringList platformPluginArguments(const QString &platformName);
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index ce06c8e00b..500b475d1d 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -228,7 +228,18 @@ QUrl QFileSelector::select(const QUrl &filePath) const
QString selectedPath = d->select(equivalentPath);
ret.setPath(selectedPath.remove(0, scheme.size()));
} else {
+ // we need to store the original query and fragment, since toLocalFile() will strip it off
+ QString frag;
+ if (ret.hasFragment())
+ frag = ret.fragment();
+ QString query;
+ if (ret.hasQuery())
+ query= ret.query();
ret = QUrl::fromLocalFile(d->select(ret.toLocalFile()));
+ if (!frag.isNull())
+ ret.setFragment(frag);
+ if (!query.isNull())
+ ret.setQuery(query);
}
return ret;
}
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index 6b51eb65d9..15b69acbd4 100644
--- a/src/corelib/kernel/qcore_mac_objc.mm
+++ b/src/corelib/kernel/qcore_mac_objc.mm
@@ -514,5 +514,36 @@ Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version);
// -------------------------------------------------------------------------
+void QMacKeyValueObserver::addObserver()
+{
+ [object addObserver:observer forKeyPath:keyPath
+ options:NSKeyValueObservingOptionNew context:callback.get()];
+}
+
+void QMacKeyValueObserver::removeObserver() {
+ if (object)
+ [object removeObserver:observer forKeyPath:keyPath context:callback.get()];
+ object = nil;
+}
+
+KeyValueObserver *QMacKeyValueObserver::observer = [[KeyValueObserver alloc] init];
+
+QT_END_NAMESPACE
+@implementation KeyValueObserver
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
+ change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
+{
+ Q_UNUSED(keyPath);
+ Q_UNUSED(object);
+ Q_UNUSED(change);
+
+ (*reinterpret_cast<QMacKeyValueObserver::Callback*>(context))();
+}
+@end
+QT_BEGIN_NAMESPACE
+
+// -------------------------------------------------------------------------
+
+
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 920105ee9e..0e1a5fe345 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -67,6 +67,7 @@
#ifdef __OBJC__
#include <Foundation/Foundation.h>
+#include <functional>
#endif
#include "qstring.h"
@@ -295,13 +296,13 @@ QT_MAC_WEAK_IMPORT(_os_activity_current);
// -------------------------------------------------------------------------
#if defined( __OBJC__)
-class QMacScopedObserver
+class QMacNotificationObserver
{
public:
- QMacScopedObserver() {}
+ QMacNotificationObserver() {}
template<typename Functor>
- QMacScopedObserver(id object, NSNotificationName name, Functor callback) {
+ QMacNotificationObserver(id object, NSNotificationName name, Functor callback) {
observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
object:object queue:nil usingBlock:^(NSNotification *) {
callback();
@@ -309,13 +310,13 @@ public:
];
}
- QMacScopedObserver(const QMacScopedObserver& other) = delete;
- QMacScopedObserver(QMacScopedObserver&& other) : observer(other.observer) {
+ QMacNotificationObserver(const QMacNotificationObserver& other) = delete;
+ QMacNotificationObserver(QMacNotificationObserver&& other) : observer(other.observer) {
other.observer = nil;
}
- QMacScopedObserver &operator=(const QMacScopedObserver& other) = delete;
- QMacScopedObserver &operator=(QMacScopedObserver&& other) {
+ QMacNotificationObserver &operator=(const QMacNotificationObserver& other) = delete;
+ QMacNotificationObserver &operator=(QMacNotificationObserver&& other) {
if (this != &other) {
remove();
observer = other.observer;
@@ -329,11 +330,65 @@ public:
[[NSNotificationCenter defaultCenter] removeObserver:observer];
observer = nil;
}
- ~QMacScopedObserver() { remove(); }
+ ~QMacNotificationObserver() { remove(); }
private:
id observer = nil;
};
+
+QT_END_NAMESPACE
+@interface QT_MANGLE_NAMESPACE(KeyValueObserver) : NSObject
+@end
+QT_NAMESPACE_ALIAS_OBJC_CLASS(KeyValueObserver);
+QT_BEGIN_NAMESPACE
+
+class Q_CORE_EXPORT QMacKeyValueObserver
+{
+public:
+ using Callback = std::function<void()>;
+
+ QMacKeyValueObserver() {}
+
+ // Note: QMacKeyValueObserver must not outlive the object observed!
+ QMacKeyValueObserver(id object, NSString *keyPath, Callback callback)
+ : object(object), keyPath(keyPath), callback(new Callback(callback)) { addObserver(); }
+
+ QMacKeyValueObserver(const QMacKeyValueObserver &other)
+ : QMacKeyValueObserver(other.object, other.keyPath, *other.callback.get()) {}
+
+ QMacKeyValueObserver(QMacKeyValueObserver &&other) { swap(other, *this); }
+
+ ~QMacKeyValueObserver() { removeObserver(); }
+
+ QMacKeyValueObserver &operator=(const QMacKeyValueObserver &other) {
+ QMacKeyValueObserver tmp(other);
+ swap(tmp, *this);
+ return *this;
+ }
+
+ QMacKeyValueObserver &operator=(QMacKeyValueObserver &&other) {
+ QMacKeyValueObserver tmp(std::move(other));
+ swap(tmp, *this);
+ return *this;
+ }
+
+ void removeObserver();
+
+private:
+ void swap(QMacKeyValueObserver &first, QMacKeyValueObserver &second) {
+ std::swap(first.object, second.object);
+ std::swap(first.keyPath, second.keyPath);
+ std::swap(first.callback, second.callback);
+ }
+
+ void addObserver();
+
+ id object = nil;
+ NSString *keyPath = nullptr;
+ std::unique_ptr<Callback> callback;
+
+ static KeyValueObserver *observer;
+};
#endif
// -------------------------------------------------------------------------
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index a48a7c80f2..d62188a49c 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -120,6 +120,7 @@
#ifdef Q_OS_WASM
#include <emscripten.h>
+#include <emscripten/val.h>
#endif
#ifdef QT_BOOTSTRAPPED
@@ -799,6 +800,10 @@ void QCoreApplicationPrivate::init()
Module.print(err);
});
);
+
+#if QT_CONFIG(thread)
+ QThreadPrivate::idealThreadCount = emscripten::val::global("navigator")["hardwareConcurrency"].as<int>();
+#endif
#endif
// Store app name/version (so they're still available after QCoreApplication is destroyed)
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 12512e74c5..ad5e1163bf 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -119,6 +119,7 @@ public:
class Q_CORE_EXPORT QObject
{
Q_OBJECT
+
Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged)
Q_DECLARE_PRIVATE(QObject)
@@ -129,7 +130,7 @@ public:
virtual bool event(QEvent *event);
virtual bool eventFilter(QObject *watched, QEvent *event);
-#if defined(QT_NO_TRANSLATION)
+#if defined(QT_NO_TRANSLATION) || defined(Q_CLANG_QDOC)
static QString tr(const char *sourceText, const char * = nullptr, int = -1)
{ return QString::fromUtf8(sourceText); }
#if QT_DEPRECATED_SINCE(5, 0)
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 0bceab6fb4..4d5ac4dcb2 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -138,6 +138,10 @@ class QString;
# define QT_TR_FUNCTIONS
#endif
+#ifdef Q_CLANG_QDOC
+#define QT_TR_FUNCTIONS
+#endif
+
// ### Qt6: remove
#define Q_OBJECT_CHECK /* empty, unused since Qt 5.2 */
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 209225de98..fe54ec8f07 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -195,6 +195,9 @@ public:
int waiters;
bool terminationEnabled, terminatePending;
#endif // Q_OS_WIN
+#ifdef Q_OS_WASM
+ static int idealThreadCount;
+#endif
QThreadData *data;
static QAbstractEventDispatcher *createEventDispatcher(QThreadData *data);
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 2bcc31e423..978c18c1b6 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -100,10 +100,6 @@
#include <sys/neutrino.h>
#endif
-#if defined(Q_OS_WASM)
-#include <emscripten/val.h>
-#endif
-
QT_BEGIN_NAMESPACE
#if QT_CONFIG(thread)
@@ -457,6 +453,10 @@ Qt::HANDLE QThread::currentThreadId() noexcept
# define _SC_NPROCESSORS_ONLN 84
#endif
+#ifdef Q_OS_WASM
+int QThreadPrivate::idealThreadCount = 1;
+#endif
+
int QThread::idealThreadCount() noexcept
{
int cores = 1;
@@ -506,7 +506,7 @@ int QThread::idealThreadCount() noexcept
cores = 1;
# endif
#elif defined(Q_OS_WASM)
- cores = emscripten::val::global("navigator")["hardwareConcurrency"].as<int>();
+ cores = QThreadPrivate::idealThreadCount;
#else
// the rest: Linux, Solaris, AIX, Tru64
cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 74b7966fa7..a18bc1c498 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -334,19 +334,17 @@ static constexpr int daysInUsualMonth(int month) // (February isn't usual.)
\brief The QDate class provides date functions.
- A QDate object encodes a calendar date, i.e. year, month, and day numbers,
- in the proleptic Gregorian calendar by default. It can read the current date
- from the system clock. It provides functions for comparing dates, and for
- manipulating dates. For example, it is possible to add and subtract days,
- months, and years to dates.
+ A QDate object represents a particular date. This can be expressed as a
+ calendar date, i.e. year, month, and day numbers, in the proleptic Gregorian
+ calendar.
A QDate object is typically created by giving the year, month, and day
- numbers explicitly. Note that QDate interprets two digit years as presented,
- i.e., as years 0 through 99, without adding any offset. A QDate can also be
- constructed with the static function currentDate(), which creates a QDate
- object containing the system clock's date. An explicit date can also be set
- using setDate(). The fromString() function returns a QDate given a string
- and a date format which is used to interpret the date within the string.
+ numbers explicitly. Note that QDate interprets year numbers less than 100 as
+ presented, i.e., as years 1 through 99, without adding any offset. The
+ static function currentDate() creates a QDate object containing the date
+ read from the system clock. An explicit date can also be set using
+ setDate(). The fromString() function returns a QDate given a string and a
+ date format which is used to interpret the date within the string.
The year(), month(), and day() functions provide access to the
year, month, and day numbers. Also, dayOfWeek() and dayOfYear()
@@ -380,7 +378,7 @@ static constexpr int daysInUsualMonth(int month) // (February isn't usual.)
every day in a contiguous range, with 24 November 4714 BCE in the Gregorian
calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar).
As well as being an efficient and accurate way of storing an absolute date,
- it is suitable for converting a Date into other calendar systems such as
+ it is suitable for converting a date into other calendar systems such as
Hebrew, Islamic or Chinese. The Julian Day number can be obtained using
QDate::toJulianDay() and can be set using QDate::fromJulianDay().
@@ -1693,12 +1691,10 @@ bool QDate::isLeapYear(int y)
Unlike QDateTime, QTime knows nothing about time zones or
daylight-saving time (DST).
- A QTime object is typically created either by giving the number
- of hours, minutes, seconds, and milliseconds explicitly, or by
- using the static function currentTime(), which creates a QTime
- object that contains the system's local time. Note that the
- accuracy depends on the accuracy of the underlying operating
- system; not all systems provide 1-millisecond accuracy.
+ A QTime object is typically created either by giving the number of hours,
+ minutes, seconds, and milliseconds explicitly, or by using the static
+ function currentTime(), which creates a QTime object that represents the
+ system's local time.
The hour(), minute(), second(), and msec() functions provide
access to the number of hours, minutes, seconds, and milliseconds
@@ -2155,6 +2151,12 @@ int QTime::msecsTo(const QTime &t) const
Note that the accuracy depends on the accuracy of the underlying
operating system; not all systems provide 1-millisecond accuracy.
+
+ Furthermore, currentTime() only increases within each day; it shall drop by
+ 24 hours each time midnight passes; and, beside this, changes in it may not
+ correspond to elapsed time, if a daylight-saving transition intervenes.
+
+ \sa QDateTime::currentDateTime(), QDateTime::currentDateTimeUtc()
*/
#if QT_CONFIG(datestring)
@@ -3270,15 +3272,30 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
provides functions for comparing datetimes and for manipulating a
datetime by adding a number of seconds, days, months, or years.
- A QDateTime object is typically created either by giving a date
- and time explicitly in the constructor, or by using the static
- function currentDateTime() that returns a QDateTime object set
- to the system clock's time. The date and time can be changed with
- setDate() and setTime(). A datetime can also be set using the
- setTime_t() function that takes a POSIX-standard "number of
- seconds since 00:00:00 on January 1, 1970" value. The fromString()
- function returns a QDateTime, given a string and a date format
- used to interpret the date within the string.
+ QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local
+ time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset
+ from UTC} or to a specified \l{{Qt::TimeZone}{time zone}, in conjunction
+ with the QTimeZone class. For example, a time zone of "Europe/Berlin" will
+ apply the daylight-saving rules as used in Germany since 1970. In contrast,
+ an offset from UTC of +3600 seconds is one hour ahead of UTC (usually
+ written in ISO standard notation as "UTC+01:00"), with no daylight-saving
+ offset or changes. When using either local time or a specified time zone,
+ time-zone transitions such as the starts and ends of daylight-saving time
+ (DST) are taken into account. The choice of system used to represent a
+ datetime is described as its "timespec".
+
+ A QDateTime object is typically created either by giving a date and time
+ explicitly in the constructor, or by using a static function such as
+ currentDateTime() or fromMSecsSinceEpoch(). The date and time can be changed
+ with setDate() and setTime(). A datetime can also be set using the
+ setMSecsSinceEpoch() function that takes the time, in milliseconds, since
+ 00:00:00 on January 1, 1970. The fromString() function returns a QDateTime,
+ given a string and a date format used to interpret the date within the
+ string.
+
+ QDateTime::currentDateTime() returns a QDateTime that expresses the current
+ time with respect to local time. QDateTime::currentDateTimeUtc() returns a
+ QDateTime that expresses the current time with respect to UTC.
The date() and time() functions provide access to the date and
time parts of the datetime. The same information is provided in
@@ -3289,18 +3306,20 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
later.
You can increment (or decrement) a datetime by a given number of
- milliseconds using addMSecs(), seconds using addSecs(), or days
- using addDays(). Similarly, you can use addMonths() and addYears().
- The daysTo() function returns the number of days between two datetimes,
- secsTo() returns the number of seconds between two datetimes, and
- msecsTo() returns the number of milliseconds between two datetimes.
-
- QDateTime can store datetimes as \l{Qt::LocalTime}{local time} or
- as \l{Qt::UTC}{UTC}. QDateTime::currentDateTime() returns a
- QDateTime expressed as local time; use toUTC() to convert it to
- UTC. You can also use timeSpec() to find out if a QDateTime
- object stores a UTC time or a local time. Operations such as
- addSecs() and secsTo() are aware of daylight-saving time (DST).
+ milliseconds using addMSecs(), seconds using addSecs(), or days using
+ addDays(). Similarly, you can use addMonths() and addYears(). The daysTo()
+ function returns the number of days between two datetimes, secsTo() returns
+ the number of seconds between two datetimes, and msecsTo() returns the
+ number of milliseconds between two datetimes. These operations are aware of
+ daylight-saving time (DST) and other time-zone transitions, where
+ applicable.
+
+ Use toTimeSpec() to express a datetime in local time or UTC,
+ toOffsetFromUtc() to express in terms of an offset from UTC, or toTimeZone()
+ to express it with respect to a general time zone. You can use timeSpec() to
+ find out what time-spec a QDateTime object stores its time relative to. When
+ that is Qt::TimeZone, you can use timeZone() to find out which zone it is
+ using.
\note QDateTime does not account for leap seconds.
@@ -3314,67 +3333,55 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
\section2 Range of Valid Dates
- The range of valid values able to be stored in QDateTime is dependent on
- the internal storage implementation. QDateTime is currently stored in a
- qint64 as a serial msecs value encoding the date and time. This restricts
- the date range to about +/- 292 million years, compared to the QDate range
- of +/- 2 billion years. Care must be taken when creating a QDateTime with
- extreme values that you do not overflow the storage. The exact range of
- supported values varies depending on the Qt::TimeSpec and time zone.
+ The range of values that QDateTime can represent is dependent on the
+ internal storage implementation. QDateTime is currently stored in a qint64
+ as a serial msecs value encoding the date and time. This restricts the date
+ range to about +/- 292 million years, compared to the QDate range of +/- 2
+ billion years. Care must be taken when creating a QDateTime with extreme
+ values that you do not overflow the storage. The exact range of supported
+ values varies depending on the Qt::TimeSpec and time zone.
+
+ \section2 Use of Timezones
+
+ QDateTime uses the system's time zone information to determine the current
+ local time zone and its offset from UTC. If the system is not configured
+ correctly or not up-to-date, QDateTime will give wrong results.
- \section2 Use of System Timezone
+ QDateTime likewise uses system-provided information to determine the offsets
+ of other timezones from UTC. If this information is incomplete or out of
+ date, QDateTime will give wrong results. See the QTimeZone documentation for
+ more details.
- QDateTime uses the system's time zone information to determine the
- offset of local time from UTC. If the system is not configured
- correctly or not up-to-date, QDateTime will give wrong results as
- well.
+ On modern Unix systems, this means QDateTime usually has accurate
+ information about historical transitions (including DST, see below) whenever
+ possible. On Windows, where the system doesn't support historical timezone
+ data, historical accuracy is not maintained with respect to timezone
+ transitions, notably including DST.
\section2 Daylight-Saving Time (DST)
- QDateTime takes into account the system's time zone information
- when dealing with DST. On modern Unix systems, this means it
- applies the correct historical DST data whenever possible. On
- Windows, where the system doesn't support historical DST data,
- historical accuracy is not maintained with respect to DST.
-
- The range of valid dates taking DST into account is 1970-01-01 to
- the present, and rules are in place for handling DST correctly
- until 2037-12-31, but these could change. For dates falling
- outside that range, QDateTime makes a \e{best guess} using the
- rules for year 1970 or 2037, but we can't guarantee accuracy. This
- means QDateTime doesn't take into account changes in a locale's
- time zone before 1970, even if the system's time zone database
- supports that information.
-
- QDateTime takes into consideration the Standard Time to Daylight-Saving Time
- transition. For example if the transition is at 2am and the clock goes
- forward to 3am, then there is a "missing" hour from 02:00:00 to 02:59:59.999
- which QDateTime considers to be invalid. Any date maths performed
- will take this missing hour into account and return a valid result.
-
- \section2 Offset From UTC
-
- A Qt::TimeSpec of Qt::OffsetFromUTC is also supported. This allows you
- to define a QDateTime relative to UTC at a fixed offset of a given number
- of seconds from UTC. For example, an offset of +3600 seconds is one hour
- ahead of UTC and is usually written in ISO standard notation as
- "UTC+01:00". Daylight-Saving Time never applies with this TimeSpec.
-
- There is no explicit size restriction to the offset seconds, but there is
- an implicit limit imposed when using the toString() and fromString()
- methods which use a format of [+|-]hh:mm, effectively limiting the range
- to +/- 99 hours and 59 minutes and whole minutes only. Note that currently
- no time zone lies outside the range of +/- 14 hours.
-
- \section2 Time Zone Support
-
- A Qt::TimeSpec of Qt::TimeZone is also supported in conjunction with the
- QTimeZone class. This allows you to define a datetime in a named time zone
- adhering to a consistent set of daylight-saving transition rules. For
- example a time zone of "Europe/Berlin" will apply the daylight-saving
- rules as used in Germany since 1970. Note that the transition rules
- applied depend on the platform support. See the QTimeZone documentation
- for more details.
+ QDateTime takes into account transitions between Standard Time and
+ Daylight-Saving Time. For example, if the transition is at 2am and the clock
+ goes forward to 3am, then there is a "missing" hour from 02:00:00 to
+ 02:59:59.999 which QDateTime considers to be invalid. Any date arithmetic
+ performed will take this missing hour into account and return a valid
+ result. For example, adding one minute to 01:59:59 will get 03:00:00.
+
+ The range of valid dates taking DST into account is 1970-01-01 to the
+ present, and rules are in place for handling DST correctly until 2037-12-31,
+ but these could change. For dates falling outside that range, QDateTime
+ makes a \e{best guess} using the rules for year 1970 or 2037, but we can't
+ guarantee accuracy. This means QDateTime doesn't take into account changes
+ in a time zone before 1970, even if the system's time zone database provides
+ that information.
+
+ \section2 Offsets From UTC
+
+ There is no explicit size restriction on an offset from UTC, but there is an
+ implicit limit imposed when using the toString() and fromString() methods
+ which use a [+|-]hh:mm format, effectively limiting the range to +/- 99
+ hours and 59 minutes and whole minutes only. Note that currently no time
+ zone lies outside the range of +/- 14 hours.
\sa QDate, QTime, QDateTimeEdit, QTimeZone
*/
@@ -4497,7 +4504,7 @@ qint64 QDateTime::msecsTo(const QDateTime &other) const
Example:
\snippet code/src_corelib_tools_qdatetime.cpp 16
- \sa timeSpec(), toTimeZone(), toUTC(), toLocalTime()
+ \sa timeSpec(), toTimeZone(), toOffsetFromUtc()
*/
QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index 2c845b1bce..1c74305e3d 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -50,6 +50,12 @@
#include <qdebug.h>
#include <algorithm>
+#include <errno.h>
+#include <limits.h>
+#if !defined(Q_OS_INTEGRITY)
+#include <sys/param.h> // to use MAXSYMLINKS constant
+#endif
+#include <unistd.h> // to use _SC_SYMLOOP_MAX constant
QT_BEGIN_NAMESPACE
@@ -1057,6 +1063,27 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecs
return last > m_tranTimes.cbegin() ? dataForTzTransition(*--last) : invalidData();
}
+static long getSymloopMax()
+{
+#if defined(SYMLOOP_MAX)
+ return SYMLOOP_MAX; // if defined, at runtime it can only be greater than this, so this is a safe bet
+#else
+ errno = 0;
+ long result = sysconf(_SC_SYMLOOP_MAX);
+ if (result >= 0)
+ return result;
+ // result is -1, meaning either error or no limit
+ Q_ASSERT(!errno); // ... but it can't be an error, POSIX mandates _SC_SYMLOOP_MAX
+
+ // therefore we can make up our own limit
+# if defined(MAXSYMLINKS)
+ return MAXSYMLINKS;
+# else
+ return 8;
+# endif
+#endif
+}
+
// TODO Could cache the value and monitor the required files for any changes
QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
{
@@ -1074,12 +1101,18 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
// On most distros /etc/localtime is a symlink to a real file so extract name from the path
if (ianaId.isEmpty()) {
- const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
- if (!path.isEmpty()) {
+ const QLatin1String zoneinfo("/zoneinfo/");
+ QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
+ int index = -1;
+ long iteration = getSymloopMax();
+ // Symlink may point to another symlink etc. before being under zoneinfo/
+ // We stop on the first path under /zoneinfo/, even if it is itself a
+ // symlink, like America/Montreal pointing to America/Toronto
+ while (iteration-- > 0 && !path.isEmpty() && (index = path.indexOf(zoneinfo)) < 0)
+ path = QFile::symLinkTarget(path);
+ if (index >= 0) {
// /etc/localtime is a symlink to the current TZ file, so extract from path
- int index = path.indexOf(QLatin1String("/zoneinfo/"));
- if (index != -1)
- ianaId = path.mid(index + 10).toUtf8();
+ ianaId = path.mid(index + zoneinfo.size()).toUtf8();
}
}
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index 132ff48846..e64610b93b 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -822,7 +822,7 @@ static QString wc2rx(const QString &wc_str, const bool enableEscaping)
if (wc[i] == QLatin1Char('^'))
rx += wc[i++];
if (i < wclen) {
- if (rx[i] == QLatin1Char(']'))
+ if (wc[i] == QLatin1Char(']'))
rx += wc[i++];
while (i < wclen && wc[i] != QLatin1Char(']')) {
if (wc[i] == QLatin1Char('\\'))