summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/CMakeLists.txt18
-rw-r--r--src/corelib/Qt6AndroidMacros.cmake68
-rw-r--r--src/corelib/Qt6CTestMacros.cmake141
-rw-r--r--src/corelib/Qt6CoreConfigExtras.cmake.in3
-rw-r--r--src/corelib/Qt6CoreDeploySupport.cmake2
-rw-r--r--src/corelib/Qt6CoreMacros.cmake563
-rw-r--r--src/corelib/Qt6WasmMacros.cmake45
-rw-r--r--src/corelib/animation/qabstractanimation.cpp10
-rw-r--r--src/corelib/animation/qabstractanimation_p.h2
-rw-r--r--src/corelib/animation/qanimationgroup.cpp4
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp4
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.cpp6
-rw-r--r--src/corelib/animation/qvariantanimation.cpp12
-rw-r--r--src/corelib/compat/removed_api.cpp21
-rw-r--r--src/corelib/configure.cmake2
-rw-r--r--src/corelib/doc/snippets/code/doc_src_containers.cpp71
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qplugin.pro4
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp94
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp6
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp3
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp6
-rw-r--r--src/corelib/doc/snippets/qstringlist/main.cpp18
-rw-r--r--src/corelib/doc/src/animation.qdoc338
-rw-r--r--src/corelib/doc/src/cbor.qdoc78
-rw-r--r--src/corelib/doc/src/cmake/cmake-commands.qdoc1
-rw-r--r--src/corelib/doc/src/cmake/cmake-configure-variables.qdoc185
-rw-r--r--src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc10
-rw-r--r--src/corelib/doc/src/cmake/cmake-properties.qdoc79
-rw-r--r--src/corelib/doc/src/cmake/qt_add_big_resources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_executable.qdoc31
-rw-r--r--src/corelib/doc/src/cmake/qt_add_library.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_plugin.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_resources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_finalize_project.qdoc21
-rw-r--r--src/corelib/doc/src/cmake/qt_finalize_target.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_generate_moc.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_import_plugins.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc2
-rw-r--r--src/corelib/doc/src/containers.qdoc74
-rw-r--r--src/corelib/doc/src/datastreamformat.qdoc3
-rw-r--r--src/corelib/doc/src/external-resources.qdoc30
-rw-r--r--src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc13
-rw-r--r--src/corelib/doc/src/io.qdoc2
-rw-r--r--src/corelib/doc/src/qtcore-index.qdoc1
-rw-r--r--src/corelib/doc/src/qtcore.qdoc14
-rw-r--r--src/corelib/doc/src/qtserialization.qdoc138
-rw-r--r--src/corelib/doc/src/resource-system.qdoc9
-rw-r--r--src/corelib/global/q20algorithm.h91
-rw-r--r--src/corelib/global/q20functional.h6
-rw-r--r--src/corelib/global/q20iterator.h6
-rw-r--r--src/corelib/global/q23functional.h6
-rw-r--r--src/corelib/global/qcompare.qdoc2
-rw-r--r--src/corelib/global/qcompilerdetection.h23
-rw-r--r--src/corelib/global/qflags.h10
-rw-r--r--src/corelib/global/qforeach.h12
-rw-r--r--src/corelib/global/qglobal.cpp57
-rw-r--r--src/corelib/global/qglobal.h46
-rw-r--r--src/corelib/global/qlibraryinfo.cpp4
-rw-r--r--src/corelib/global/qlogging.cpp38
-rw-r--r--src/corelib/global/qnamespace.qdoc10
-rw-r--r--src/corelib/global/qnumeric.cpp31
-rw-r--r--src/corelib/global/qnumeric.h2
-rw-r--r--src/corelib/global/qnumeric_p.h35
-rw-r--r--src/corelib/global/qoperatingsystemversion.cpp32
-rw-r--r--src/corelib/global/qoperatingsystemversion.h7
-rw-r--r--src/corelib/global/qoperatingsystemversion_darwin.mm49
-rw-r--r--src/corelib/global/qprocessordetection.h2
-rw-r--r--src/corelib/global/qrandom.cpp4
-rw-r--r--src/corelib/global/qsimd.h2
-rw-r--r--src/corelib/global/qsimd_p.h19
-rw-r--r--src/corelib/global/qtconfigmacros.h (renamed from src/corelib/global/qtnamespacemacros.h)45
-rw-r--r--src/corelib/global/qtypeinfo.h8
-rw-r--r--src/corelib/global/qversiontagging.h2
-rw-r--r--src/corelib/global/qxpfunctional.h6
-rw-r--r--src/corelib/io/qabstractfileengine.cpp11
-rw-r--r--src/corelib/io/qabstractfileengine_p.h2
-rw-r--r--src/corelib/io/qbuffer.cpp4
-rw-r--r--src/corelib/io/qdebug.cpp20
-rw-r--r--src/corelib/io/qdebug.h4
-rw-r--r--src/corelib/io/qdebug_p.h2
-rw-r--r--src/corelib/io/qdir.cpp136
-rw-r--r--src/corelib/io/qdiriterator.cpp2
-rw-r--r--src/corelib/io/qfile.cpp11
-rw-r--r--src/corelib/io/qfiledevice.cpp5
-rw-r--r--src/corelib/io/qfileinfo.cpp22
-rw-r--r--src/corelib/io/qfileselector.cpp2
-rw-r--r--src/corelib/io/qfilesystemengine.cpp6
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp8
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_kqueue.cpp2
-rw-r--r--src/corelib/io/qfilesystemwatcher_win.cpp24
-rw-r--r--src/corelib/io/qfilesystemwatcher_win_p.h5
-rw-r--r--src/corelib/io/qfsfileengine.cpp4
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp22
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp4
-rw-r--r--src/corelib/io/qipaddress.cpp12
-rw-r--r--src/corelib/io/qlockfile.h6
-rw-r--r--src/corelib/io/qloggingcategory.cpp3
-rw-r--r--src/corelib/io/qresource.cpp20
-rw-r--r--src/corelib/io/qsettings.cpp34
-rw-r--r--src/corelib/io/qsettings.h6
-rw-r--r--src/corelib/io/qsettings_p.h6
-rw-r--r--src/corelib/io/qsettings_wasm.cpp294
-rw-r--r--src/corelib/io/qstandardpaths.cpp17
-rw-r--r--src/corelib/io/qstandardpaths_android.cpp161
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp99
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp33
-rw-r--r--src/corelib/io/qtemporaryfile.cpp8
-rw-r--r--src/corelib/io/qurl.cpp91
-rw-r--r--src/corelib/io/qurlidna.cpp12
-rw-r--r--src/corelib/io/qurlquery.cpp12
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp40
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel.cpp2
-rw-r--r--src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp4
-rw-r--r--src/corelib/itemmodels/qidentityproxymodel.cpp6
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp76
-rw-r--r--src/corelib/itemmodels/qsortfilterproxymodel.cpp72
-rw-r--r--src/corelib/itemmodels/qstringlistmodel.cpp8
-rw-r--r--src/corelib/itemmodels/qtransposeproxymodel.cpp4
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.cpp2
-rw-r--r--src/corelib/kernel/qapplicationstatic.h8
-rw-r--r--src/corelib/kernel/qcfsocketnotifier.cpp2
-rw-r--r--src/corelib/kernel/qcore_mac.mm49
-rw-r--r--src/corelib/kernel/qcore_mac_p.h12
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp95
-rw-r--r--src/corelib/kernel/qdeadlinetimer.h8
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib.cpp8
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp2
-rw-r--r--src/corelib/kernel/qeventdispatcher_wasm.cpp90
-rw-r--r--src/corelib/kernel/qeventdispatcher_wasm_p.h1
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp4
-rw-r--r--src/corelib/kernel/qjnihelpers.cpp4
-rw-r--r--src/corelib/kernel/qjniobject.cpp7
-rw-r--r--src/corelib/kernel/qjniobject.h2
-rw-r--r--src/corelib/kernel/qmetaobject.cpp2
-rw-r--r--src/corelib/kernel/qmetatype.cpp93
-rw-r--r--src/corelib/kernel/qmetatype.h33
-rw-r--r--src/corelib/kernel/qobject.cpp43
-rw-r--r--src/corelib/kernel/qobject.h6
-rw-r--r--src/corelib/kernel/qobject_p.h2
-rw-r--r--src/corelib/kernel/qpoll.cpp5
-rw-r--r--src/corelib/kernel/qproperty.cpp107
-rw-r--r--src/corelib/kernel/qproperty.h17
-rw-r--r--src/corelib/kernel/qproperty_p.h113
-rw-r--r--src/corelib/kernel/qpropertyprivate.h17
-rw-r--r--src/corelib/kernel/qsharedmemory.cpp6
-rw-r--r--src/corelib/kernel/qt_attribution.json2
-rw-r--r--src/corelib/kernel/qtimer.cpp31
-rw-r--r--src/corelib/kernel/qtimer.h8
-rw-r--r--src/corelib/kernel/qtimer_p.h39
-rw-r--r--src/corelib/kernel/qtimerinfo_unix.cpp8
-rw-r--r--src/corelib/kernel/qtranslator.cpp17
-rw-r--r--src/corelib/kernel/qvariant.cpp37
-rw-r--r--src/corelib/mimetypes/qmimedatabase.cpp56
-rw-r--r--src/corelib/mimetypes/qmimedatabase_p.h2
-rw-r--r--src/corelib/mimetypes/qmimeglobpattern.cpp18
-rw-r--r--src/corelib/mimetypes/qmimeprovider.cpp16
-rw-r--r--src/corelib/mimetypes/qmimetype.cpp6
-rw-r--r--src/corelib/platform/android/qandroidextras.cpp20
-rw-r--r--src/corelib/platform/android/qandroidnativeinterface.cpp43
-rw-r--r--src/corelib/platform/wasm/qstdweb.cpp2
-rw-r--r--src/corelib/platform/windows/qfactorycacheregistration.cpp53
-rw-r--r--src/corelib/platform/windows/qfactorycacheregistration_p.h52
-rw-r--r--src/corelib/platform/windows/qt_winrtbase_p.h34
-rw-r--r--src/corelib/plugin/qcoffpeparser.cpp2
-rw-r--r--src/corelib/plugin/qelfparser_p.cpp7
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp2
-rw-r--r--src/corelib/plugin/qlibrary.cpp54
-rw-r--r--src/corelib/plugin/qlibrary_p.h3
-rw-r--r--src/corelib/plugin/qlibrary_unix.cpp2
-rw-r--r--src/corelib/plugin/qlibrary_win.cpp2
-rw-r--r--src/corelib/plugin/qmachparser.cpp25
-rw-r--r--src/corelib/plugin/qplugin.h6
-rw-r--r--src/corelib/plugin/qplugin.qdoc8
-rw-r--r--src/corelib/plugin/qpluginloader.cpp6
-rw-r--r--src/corelib/serialization/qcborarray.cpp4
-rw-r--r--src/corelib/serialization/qcborcommon.cpp4
-rw-r--r--src/corelib/serialization/qcbormap.cpp4
-rw-r--r--src/corelib/serialization/qcborstreamreader.cpp10
-rw-r--r--src/corelib/serialization/qcborstreamwriter.cpp2
-rw-r--r--src/corelib/serialization/qcborvalue.cpp6
-rw-r--r--src/corelib/serialization/qcborvalue.h4
-rw-r--r--src/corelib/serialization/qdatastream.cpp1
-rw-r--r--src/corelib/serialization/qjsonarray.cpp21
-rw-r--r--src/corelib/serialization/qjsondocument.cpp3
-rw-r--r--src/corelib/serialization/qjsonobject.cpp27
-rw-r--r--src/corelib/serialization/qjsonparser.cpp3
-rw-r--r--src/corelib/serialization/qjsonvalue.cpp1
-rw-r--r--src/corelib/serialization/qjsonwriter.cpp6
-rw-r--r--src/corelib/serialization/qtextstream.cpp12
-rw-r--r--src/corelib/serialization/qtextstream_p.h4
-rw-r--r--src/corelib/serialization/qxmlstream.cpp5
-rw-r--r--src/corelib/serialization/qxmlstream_p.h2
-rw-r--r--src/corelib/text/qanystringview.h16
-rw-r--r--src/corelib/text/qanystringview.qdoc83
-rw-r--r--src/corelib/text/qbytearray.cpp332
-rw-r--r--src/corelib/text/qbytearraymatcher.h29
-rw-r--r--src/corelib/text/qbytearrayview.qdoc2
-rw-r--r--src/corelib/text/qbytedata_p.h6
-rw-r--r--src/corelib/text/qchar.cpp36
-rw-r--r--src/corelib/text/qlocale.cpp243
-rw-r--r--src/corelib/text/qlocale_mac.mm6
-rw-r--r--src/corelib/text/qlocale_p.h20
-rw-r--r--src/corelib/text/qlocale_tools.cpp64
-rw-r--r--src/corelib/text/qlocale_tools_p.h13
-rw-r--r--src/corelib/text/qlocale_win.cpp46
-rw-r--r--src/corelib/text/qregularexpression.cpp6
-rw-r--r--src/corelib/text/qstring.cpp182
-rw-r--r--src/corelib/text/qstring.h41
-rw-r--r--src/corelib/text/qstringconverter.cpp40
-rw-r--r--src/corelib/text/qstringconverter_base.h2
-rw-r--r--src/corelib/text/qstringconverter_p.h13
-rw-r--r--src/corelib/text/qstringlist.cpp24
-rw-r--r--src/corelib/text/qstringlist.h2
-rw-r--r--src/corelib/text/qstringview.cpp4
-rw-r--r--src/corelib/text/qt_attribution.json2
-rw-r--r--src/corelib/text/qtextboundaryfinder.cpp4
-rw-r--r--src/corelib/text/qunicodetools.cpp47
-rw-r--r--src/corelib/text/qutf8stringview.qdoc2
-rw-r--r--src/corelib/thread/qatomic.cpp82
-rw-r--r--src/corelib/thread/qatomic.h5
-rw-r--r--src/corelib/thread/qfuture_impl.h12
-rw-r--r--src/corelib/thread/qfutureinterface.cpp60
-rw-r--r--src/corelib/thread/qfutureinterface.h4
-rw-r--r--src/corelib/thread/qfutureinterface_p.h5
-rw-r--r--src/corelib/thread/qfuturesynchronizer.h4
-rw-r--r--src/corelib/thread/qlocking_p.h7
-rw-r--r--src/corelib/thread/qmutex.cpp4
-rw-r--r--src/corelib/thread/qmutex.h8
-rw-r--r--src/corelib/thread/qmutex_p.h9
-rw-r--r--src/corelib/thread/qmutex_win.cpp30
-rw-r--r--src/corelib/thread/qpromise.h1
-rw-r--r--src/corelib/thread/qpromise.qdoc2
-rw-r--r--src/corelib/thread/qresultstore.h10
-rw-r--r--src/corelib/thread/qsemaphore.cpp5
-rw-r--r--src/corelib/thread/qthread.cpp10
-rw-r--r--src/corelib/thread/qthread.h4
-rw-r--r--src/corelib/thread/qthread_unix.cpp3
-rw-r--r--src/corelib/thread/qthreadpool.cpp34
-rw-r--r--src/corelib/thread/qthreadpool_p.h2
-rw-r--r--src/corelib/thread/qthreadstorage.cpp6
-rw-r--r--src/corelib/thread/qwaitcondition.qdoc6
-rw-r--r--src/corelib/thread/qwaitcondition_p.h7
-rw-r--r--src/corelib/thread/qwaitcondition_win.cpp4
-rw-r--r--src/corelib/time/qdatetime.cpp6
-rw-r--r--src/corelib/time/qdatetime.h19
-rw-r--r--src/corelib/time/qtimezone.cpp2
-rw-r--r--src/corelib/time/qtimezoneprivate.cpp2
-rw-r--r--src/corelib/time/qtimezoneprivate_tz.cpp43
-rw-r--r--src/corelib/tools/qatomicscopedvaluerollback_p.h11
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp18
-rw-r--r--src/corelib/tools/qcontainertools_impl.h20
-rw-r--r--src/corelib/tools/qcryptographichash.cpp62
-rw-r--r--src/corelib/tools/qeasingcurve.cpp24
-rw-r--r--src/corelib/tools/qhash.cpp39
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qhashfunctions.h30
-rw-r--r--src/corelib/tools/qlist.qdoc33
-rw-r--r--src/corelib/tools/qmap.qdoc9
-rw-r--r--src/corelib/tools/qmessageauthenticationcode.cpp37
-rw-r--r--src/corelib/tools/qoffsetstringarray_p.h25
-rw-r--r--src/corelib/tools/qpair.h3
-rw-r--r--src/corelib/tools/qset.h4
-rw-r--r--src/corelib/tools/qsharedpointer.cpp49
-rw-r--r--src/corelib/tools/qsharedpointer.h8
-rw-r--r--src/corelib/tools/qtaggedpointer.h23
-rw-r--r--src/corelib/tools/qtools_p.h5
-rw-r--r--src/corelib/tools/qvarlengtharray.h126
-rw-r--r--src/corelib/tools/qversionnumber.cpp9
286 files changed, 4668 insertions, 3021 deletions
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt
index 200c383ea5..40eb0826aa 100644
--- a/src/corelib/CMakeLists.txt
+++ b/src/corelib/CMakeLists.txt
@@ -66,15 +66,14 @@ qt_internal_add_module(Core
global/qrandom.cpp global/qrandom.h global/qrandom_p.h
global/qsysinfo.h
global/qsystemdetection.h
- global/qtnamespacemacros.h
+ global/qtconfigmacros.h
global/qtrace_p.h
global/qtypeinfo.h
global/qvolatile_p.h
global/q20algorithm.h
global/q20functional.h
- global/q23functional.h
- global/qxpfunctional.h
global/q20iterator.h
+ global/q23functional.h
global/qxpfunctional.h
io/qabstractfileengine.cpp io/qabstractfileengine_p.h
io/qbuffer.cpp io/qbuffer.h
@@ -149,7 +148,7 @@ qt_internal_add_module(Core
kernel/qsystemerror.cpp kernel/qsystemerror_p.h
kernel/qsystemsemaphore.cpp kernel/qsystemsemaphore.h kernel/qsystemsemaphore_p.h
kernel/qtestsupport_core.cpp kernel/qtestsupport_core.h
- kernel/qtimer.cpp kernel/qtimer.h
+ kernel/qtimer.cpp kernel/qtimer.h kernel/qtimer_p.h
kernel/qtranslator.cpp kernel/qtranslator.h kernel/qtranslator_p.h
kernel/qvariant.cpp kernel/qvariant.h kernel/qvariant_p.h
kernel/qvariantmap.h kernel/qvarianthash.h kernel/qvariantlist.h
@@ -494,7 +493,6 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_animation
# from the wrong DLL at runtime and crash!
qt_internal_extend_target(Core CONDITION QT_FEATURE_thread AND WIN32
SOURCES
- thread/qmutex_win.cpp
thread/qwaitcondition_win.cpp
LIBRARIES
synchronization
@@ -974,6 +972,13 @@ qt_internal_extend_target(Core CONDITION ANDROID
platform/android/qandroidnativeinterface.cpp
)
+qt_internal_extend_target(Core CONDITION WIN32
+ SOURCES
+ platform/windows/qfactorycacheregistration_p.h
+ platform/windows/qfactorycacheregistration.cpp
+ platform/windows/qt_winrtbase_p.h
+)
+
qt_internal_extend_target(Core CONDITION HAIKU AND NOT ANDROID
SOURCES
io/qstandardpaths_haiku.cpp
@@ -1044,7 +1049,7 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_library AND UNIX AND NOT APP
plugin/qlibrary_unix.cpp
)
-qt_internal_extend_target(Core CONDITION QT_FEATURE_dlopen AND QT_FEATURE_library
+qt_internal_extend_target(Core CONDITION QT_FEATURE_dlopen
LIBRARIES
${CMAKE_DL_LIBS}
)
@@ -1282,7 +1287,6 @@ qt_internal_extend_target(Core CONDITION WASM
set_source_files_properties(
thread/qmutex_mac.cpp
thread/qmutex_unix.cpp
- thread/qmutex_win.cpp
PROPERTIES HEADER_FILE_ONLY ON) # special case: These files are included by qmutex.cpp!
diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake
index 58453f0c5f..4a225181ec 100644
--- a/src/corelib/Qt6AndroidMacros.cmake
+++ b/src/corelib/Qt6AndroidMacros.cmake
@@ -254,6 +254,9 @@ function(qt6_android_generate_deployment_settings target)
if(COMMAND _qt_internal_generate_android_qml_deployment_settings)
_qt_internal_generate_android_qml_deployment_settings(file_contents ${target})
+ else()
+ string(APPEND file_contents
+ " \"qml-skip-import-scanning\": true,\n")
endif()
# Override rcc binary path
@@ -271,6 +274,12 @@ function(qt6_android_generate_deployment_settings target)
string(APPEND file_contents
" \"extraPrefixDirs\" : [ ${extra_prefix_list} ],\n")
+ # Create an empty target for the cases when we need to generate deployment setting but
+ # qt_finalize_project is never called.
+ if(NOT TARGET _qt_internal_apk_dependencies AND NOT QT_NO_COLLECT_BUILD_TREE_APK_DEPS)
+ add_custom_target(_qt_internal_apk_dependencies)
+ endif()
+
# Extra library paths that could be used as a dependency lookup path by androiddeployqt.
#
# Unlike 'extraPrefixDirs', the 'extraLibraryDirs' key doesn't expect the 'lib' subfolder
@@ -388,9 +397,14 @@ function(qt6_android_add_apk_target target)
COMMENT "Copying ${target} binary to apk folder"
)
+ set(sign_apk "")
if(QT_ANDROID_SIGN_APK)
set(sign_apk "--sign")
endif()
+ set(sign_aab "")
+ if(QT_ANDROID_SIGN_AAB)
+ set(sign_aab "--sign")
+ endif()
set(extra_args "")
if(QT_INTERNAL_NO_ANDROID_RCC_BUNDLE_CLEANUP)
@@ -426,8 +440,8 @@ function(qt6_android_add_apk_target target)
--apk "${apk_final_file_path}"
--depfile "${dep_file_path}"
--builddir "${relative_to_dir}"
- ${sign_apk}
${extra_args}
+ ${sign_apk}
COMMENT "Creating APK for ${target}"
DEPENDS "${target}" "${deployment_file}" ${extra_deps}
DEPFILE "${dep_file_path}"
@@ -444,9 +458,10 @@ function(qt6_android_add_apk_target target)
--input ${deployment_file}
--output ${apk_final_dir}
--apk ${apk_final_file_path}
- ${sign_apk}
${extra_args}
+ ${sign_apk}
COMMENT "Creating APK for ${target}"
+ VERBATIM
)
endif()
@@ -460,6 +475,7 @@ function(qt6_android_add_apk_target target)
--output ${apk_final_dir}
--apk ${apk_final_file_path}
--aab
+ ${sign_aab}
${extra_args}
COMMENT "Creating AAB for ${target}"
)
@@ -545,8 +561,8 @@ endfunction()
# The function collects all known non-imported shared libraries that are created in the build tree.
# It uses the CMake DEFER CALL feature if the CMAKE_VERSION is greater
-# than or equal to 3.18.
-# Note: Users that use cmake version less that 3.18 need to call qt_finalize_project
+# than or equal to 3.19.
+# Note: Users that use cmake version less that 3.19 need to call qt_finalize_project
# in the end of a project's top-level CMakeLists.txt.
function(_qt_internal_collect_apk_dependencies_defer)
# User opted-out the functionality
@@ -560,13 +576,14 @@ function(_qt_internal_collect_apk_dependencies_defer)
endif()
set_property(GLOBAL PROPERTY _qt_is_collect_apk_dependencies_defer_called TRUE)
- if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
+ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
cmake_language(EVAL CODE "cmake_language(DEFER DIRECTORY \"${CMAKE_SOURCE_DIR}\"
CALL _qt_internal_collect_apk_dependencies)")
else()
# User don't want to see the warning
if(NOT QT_NO_WARN_BUILD_TREE_APK_DEPS)
- message(WARNING "CMake version you use is less than 3.18. APK dependencies, that are a"
+ message(WARNING
+ "The CMake version you use is less than 3.19. APK dependencies, that are a"
" part of the project tree, might not be collected correctly."
" Please call qt_finalize_project in the end of a project's top-level"
" CMakeLists.txt file to make sure that all the APK dependencies are"
@@ -577,8 +594,8 @@ function(_qt_internal_collect_apk_dependencies_defer)
endif()
endfunction()
-# The function collects shared libraries from the build system tree, that might be dependencies for
-# the main apk targets.
+# The function collects project-built shared libraries that might be dependencies for
+# the main apk targets. It stores their locations in a global custom target property.
function(_qt_internal_collect_apk_dependencies)
# User opted-out the functionality
if(QT_NO_COLLECT_BUILD_TREE_APK_DEPS)
@@ -621,8 +638,8 @@ function(_qt_internal_collect_apk_dependencies)
)
endfunction()
-# The function recursively goes through the project subfolders and collects targets that supposed to
-# be shared libraries of any kind.
+# This function recursively walks the current directory and its subdirectories to collect shared
+# library targets built in those directories.
function(_qt_internal_collect_buildsystem_shared_libraries out_var subdir)
set(result "")
get_directory_property(buildsystem_targets DIRECTORY ${subdir} BUILDSYSTEM_TARGETS)
@@ -960,18 +977,38 @@ function(_qt_internal_configure_android_multiabi_target target)
list(APPEND extra_cmake_args "-DANDROID_NDK_ROOT=${ANDROID_NDK}")
endif()
+ if(DEFINED QT_NO_PACKAGE_VERSION_CHECK)
+ list(APPEND extra_cmake_args "-DQT_NO_PACKAGE_VERSION_CHECK=${QT_NO_PACKAGE_VERSION_CHECK}")
+ endif()
+
+ if(DEFINED QT_HOST_PATH_CMAKE_DIR)
+ list(APPEND extra_cmake_args "-DQT_HOST_PATH_CMAKE_DIR=${QT_HOST_PATH_CMAKE_DIR}")
+ endif()
+
if(CMAKE_MAKE_PROGRAM)
list(APPEND extra_cmake_args "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
endif()
if(CMAKE_C_COMPILER_LAUNCHER)
- list(APPEND extra_cmake_args "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}")
+ list(JOIN CMAKE_C_COMPILER_LAUNCHER "$<SEMICOLON>"
+ compiler_launcher)
+ list(APPEND extra_cmake_args
+ "-DCMAKE_C_COMPILER_LAUNCHER=${compiler_launcher}")
endif()
if(CMAKE_CXX_COMPILER_LAUNCHER)
- list(APPEND extra_cmake_args "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
+ list(JOIN CMAKE_CXX_COMPILER_LAUNCHER "$<SEMICOLON>"
+ compiler_launcher)
+ list(APPEND extra_cmake_args
+ "-DCMAKE_CXX_COMPILER_LAUNCHER=${compiler_launcher}")
endif()
+ unset(user_cmake_args)
+ foreach(var IN LISTS QT_ANDROID_MULTI_ABI_FORWARD_VARS)
+ string(REPLACE ";" "$<SEMICOLON>" var_value "${${var}}")
+ list(APPEND user_cmake_args "-D${var}=${var_value}")
+ endforeach()
+
set(missing_qt_abi_toolchains "")
set(previous_copy_apk_dependencies_target ${target})
# Create external projects for each android ABI except the main one.
@@ -995,13 +1032,18 @@ function(_qt_internal_configure_android_multiabi_target target)
ExternalProject_Add("qt_internal_android_${abi}"
SOURCE_DIR "${CMAKE_SOURCE_DIR}"
BINARY_DIR "${android_abi_build_dir}"
- CMAKE_ARGS
+ CONFIGURE_COMMAND
+ "${CMAKE_COMMAND}"
+ "-G${CMAKE_GENERATOR}"
"-DCMAKE_TOOLCHAIN_FILE=${qt_abi_toolchain_path}"
"-DQT_HOST_PATH=${QT_HOST_PATH}"
"-DQT_IS_ANDROID_MULTI_ABI_EXTERNAL_PROJECT=ON"
"-DQT_INTERNAL_ANDROID_MULTI_ABI_BINARY_DIR=${CMAKE_BINARY_DIR}"
"${config_arg}"
"${extra_cmake_args}"
+ "${user_cmake_args}"
+ "-B" "${android_abi_build_dir}"
+ "-S" "${CMAKE_SOURCE_DIR}"
EXCLUDE_FROM_ALL TRUE
BUILD_COMMAND "" # avoid top-level build of external project
)
diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake
index 28a97f45f6..64a5d74870 100644
--- a/src/corelib/Qt6CTestMacros.cmake
+++ b/src/corelib/Qt6CTestMacros.cmake
@@ -249,7 +249,11 @@ endfunction()
# TESTNAME: a custom test name to use instead of the one derived from the source directory name
#
# BUILD_OPTIONS: a list of -D style CMake definitions to pass to ctest's --build-options (which
-# are ultimately passed to the CMake invocation of the test project)
+# are ultimately passed to the CMake invocation of the test project). You may
+# escape semicolons inside the definitions using:
+# https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument
+# so the argument containing list will look as following:
+# -DLIST_ARGUMENT=item1[[;]]item2[[;]]...itemN.
macro(_qt_internal_test_expect_pass _dir)
set(_test_option_args
SIMULATE_IN_SOURCE
@@ -411,6 +415,8 @@ macro(_qt_internal_test_expect_pass _dir)
)
endif()
+ string(REPLACE "[[;]]" "\;" _ARGS_BUILD_OPTIONS "${_ARGS_BUILD_OPTIONS}")
+
_qt_internal_get_cmake_test_configure_options(option_list)
set(ctest_command_args
--build-and-test
@@ -422,7 +428,7 @@ macro(_qt_internal_test_expect_pass _dir)
--build-makeprogram "${make_program}"
${build_project}
--build-options "${option_list}"
- ${_ARGS_BUILD_OPTIONS} ${additional_configure_args}
+ "${_ARGS_BUILD_OPTIONS}" ${additional_configure_args}
${test_command}
)
add_test(${testname} ${CMAKE_CTEST_COMMAND} ${ctest_command_args})
@@ -439,6 +445,137 @@ macro(_qt_internal_test_expect_pass _dir)
unset(__expect_pass_build_dir)
endmacro()
+# Checks if a qmake project can be built successfully. Arguments:
+#
+# TESTNAME: a custom test name to use instead of the one derived from the source directory name.
+# the name also applies to the generated build directory.
+#
+# QMAKE_OPTIONS: a list of variable assignments to pass to the qmake invocation.
+# e.g. CONFIG+=debug
+#
+# BUILD_ENVIRONMENT: a list of environment assignments to use when invoking the build tool
+function(_qt_internal_add_qmake_test dir_name)
+ set(test_option_args
+ )
+ set(test_single_args
+ TESTNAME
+ )
+ set(test_multi_args
+ QMAKE_OPTIONS
+ BUILD_ENVIRONMENT
+ )
+
+ # PARSE_ARGV parsing keeps ';' in ENVIRONMENT variables
+ cmake_parse_arguments(PARSE_ARGV 1 arg
+ "${test_option_args}"
+ "${test_single_args}"
+ "${test_multi_args}"
+ )
+
+ if(arg_TESTNAME)
+ set(testname "${arg_TESTNAME}")
+ else()
+ string(REGEX REPLACE "[/)(]" "_" testname "${dir_name}")
+ endif()
+
+ set(source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir_name}")
+ if(arg_TESTNAME)
+ set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${arg_TESTNAME}")
+ else()
+ set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${dir_name}")
+ endif()
+
+ # Find the qmake binary or the wrapper qmake script when cross-compiling..
+ if(QtBase_BINARY_DIR AND NOT QT_BUILD_STANDALONE_TESTS)
+ set(qmake_dir "${QtBase_BINARY_DIR}/${INSTALL_BINDIR}")
+ else()
+ set(qmake_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_BINS}")
+ endif()
+
+ set(qmake_path "${qmake_dir}/qmake${CMAKE_EXECUTABLE_SUFFIX}")
+
+ set(qmake_args
+ "${source_dir}"
+ ${arg_QMAKE_OPTIONS}
+ )
+
+ # Try to choose an appropriate build tool.
+ if(ENV{QT_QMAKE_TEST_BUILD_TOOL})
+ set(build_tool "$ENV{QT_QMAKE_TEST_BUILD_TOOL}")
+ elseif(MSVC)
+ set(build_tool "nmake")
+ elseif(MINGW)
+ set(build_tool "mingw32-make")
+ else()
+ set(build_tool "make")
+ endif()
+
+ set(build_tool_args "")
+ if(ENV{QT_QMAKE_TEST_BUILD_TOOL_OPTIONS})
+ set(build_tool_args "$ENV{QT_QMAKE_TEST_BUILD_TOOL_OPTIONS}")
+ endif()
+
+ # Remove any stale build dir, and create a new one on each test rerun.
+ add_test(${testname}_remove_build_dir
+ ${CMAKE_COMMAND} -E remove_directory "${build_dir}"
+ )
+ set_tests_properties(${testname}_remove_build_dir PROPERTIES
+ FIXTURES_SETUP "${testname}_ensure_clean_build_dir"
+ )
+
+ add_test(${testname}_create_build_dir
+ ${CMAKE_COMMAND} -E make_directory "${build_dir}"
+ )
+ set_tests_properties(${testname}_create_build_dir PROPERTIES
+ FIXTURES_SETUP "${testname}_ensure_clean_build_dir"
+ )
+
+ set_tests_properties(${testname}_create_build_dir
+ PROPERTIES DEPENDS ${testname}_remove_build_dir)
+
+ # Add test to call qmake.
+ #
+ # We can't use the add_test(NAME) signature to set a working directory, because that breaks
+ # when calling ctest without a -C <config> using multi-config generators, and the CI calls
+ # ctest without -C, and we use Xcode when configuring tests for iOS, which is multi-config.
+ # The plain add_test signature does not have this issue.
+ # Work around this by using a wrapper script that sets a working directory and use the plain
+ # signature.
+ # Somewhat related issue https://gitlab.kitware.com/cmake/cmake/-/issues/20283
+ set(qmake_wrapper_file "${CMAKE_CURRENT_BINARY_DIR}/run_qmake_${testname}.cmake")
+ _qt_internal_create_command_script(
+ COMMAND "${qmake_path}" ${qmake_args}
+ COMMAND_ECHO STDOUT
+ OUTPUT_FILE "${qmake_wrapper_file}"
+ WORKING_DIRECTORY "${build_dir}"
+ )
+
+ add_test(${testname}_qmake "${CMAKE_COMMAND}" "-P" "${qmake_wrapper_file}")
+
+ set_tests_properties(${testname}_qmake PROPERTIES
+ DEPENDS ${testname}_create_build_dir
+ FIXTURES_REQUIRED "${testname}_ensure_clean_build_dir"
+ FIXTURES_SETUP "${testname}_configure_project"
+ )
+
+ # Add test to build the generated qmake project.
+ set(build_tool_wrapper_file "${CMAKE_CURRENT_BINARY_DIR}/run_build_${testname}.cmake")
+ _qt_internal_create_command_script(
+ COMMAND "${build_tool}" ${build_tool_args}
+ COMMAND_ECHO STDOUT
+ OUTPUT_FILE "${build_tool_wrapper_file}"
+ WORKING_DIRECTORY "${build_dir}"
+ ENVIRONMENT ${arg_BUILD_ENVIRONMENT}
+ )
+
+ add_test(${testname} "${CMAKE_COMMAND}" "-P" "${build_tool_wrapper_file}")
+
+ set_tests_properties(${testname} PROPERTIES
+ DEPENDS ${testname}_qmake
+ FIXTURES_REQUIRED "${testname}_ensure_clean_build_dir;${testname}_configure_project"
+ )
+endfunction()
+
# Checks if the build of the test project fails.
# This test passes if the test project fails either at the
# configuring or build steps.
diff --git a/src/corelib/Qt6CoreConfigExtras.cmake.in b/src/corelib/Qt6CoreConfigExtras.cmake.in
index 8b4d3164cf..4a95625854 100644
--- a/src/corelib/Qt6CoreConfigExtras.cmake.in
+++ b/src/corelib/Qt6CoreConfigExtras.cmake.in
@@ -26,7 +26,8 @@ if (NOT QT_NO_CREATE_TARGETS)
set_property(TARGET ${__qt_core_target} PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)
endif()
-set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_GADGET_EXPORT" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
+list(APPEND CMAKE_AUTOMOC_MACRO_NAMES Q_OBJECT Q_GADGET Q_GADGET_EXPORT Q_NAMESPACE Q_NAMESPACE_EXPORT)
+list(REMOVE_DUPLICATES CMAKE_AUTOMOC_MACRO_NAMES)
# install layout information, following what qmake -query provides
get_filename_component(QT@PROJECT_VERSION_MAJOR@_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../@QT_INVERSE_CONFIG_INSTALL_DIR@ ABSOLUTE)
diff --git a/src/corelib/Qt6CoreDeploySupport.cmake b/src/corelib/Qt6CoreDeploySupport.cmake
index a9d2dfe955..c6336d0882 100644
--- a/src/corelib/Qt6CoreDeploySupport.cmake
+++ b/src/corelib/Qt6CoreDeploySupport.cmake
@@ -171,7 +171,7 @@ function(qt6_deploy_runtime_dependencies)
endif()
elseif(arg_GENERATE_QT_CONF)
get_filename_component(exe_dir "${arg_EXECUTABLE}" DIRECTORY)
- if(exe_dir STREQUAL "")
+ if(exe_dir STREQUAL "" OR exe_dir STREQUAL ".")
set(exe_dir ".")
set(prefix ".")
else()
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index cb7ddf8d81..ccfba93899 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -36,8 +36,6 @@
#
######################################
-include(CMakeParseArguments)
-
set(__qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}")
# macro used to create the names of output files preserving relative dirs
@@ -646,6 +644,7 @@ function(_qt_internal_finalize_executable target)
if(EMSCRIPTEN)
_qt_internal_wasm_add_target_helpers("${target}")
+ _qt_internal_add_wasm_extra_exported_methods("${target}")
endif()
if(IOS)
_qt_internal_finalize_ios_app("${target}")
@@ -707,521 +706,6 @@ function(qt6_finalize_target target)
endif()
endfunction()
-function(_qt_internal_handle_ios_launch_screen target)
- # Check if user provided a launch screen path via a variable.
- set(launch_screen "")
-
- # Check if the project provided a launch screen path via a variable.
- # This variable is currently in Technical Preview.
- if(QT_IOS_LAUNCH_SCREEN)
- set(launch_screen "${QT_IOS_LAUNCH_SCREEN}")
- endif()
-
- # Check if the project provided a launch screen path via a target property, it takes precedence
- # over the variable.
- # This property is currently in Technical Preview.
- get_target_property(launch_screen_from_prop "${target}" QT_IOS_LAUNCH_SCREEN)
- if(launch_screen_from_prop)
- set(launch_screen "${launch_screen_from_prop}")
- endif()
-
- # If the project hasn't provided a launch screen file path, use a copy of the template
- # that qmake uses.
- # It needs to be a copy because configure_file can't handle all the escaped double quotes
- # present in the qmake template file.
- set(is_default_launch_screen FALSE)
- if(NOT launch_screen AND NOT QT_NO_SET_DEFAULT_IOS_LAUNCH_SCREEN)
- set(is_default_launch_screen TRUE)
- set(launch_screen
- "${__qt_internal_cmake_ios_support_files_path}/LaunchScreen.storyboard")
- endif()
-
- # Check that the launch screen exists.
- if(launch_screen)
- if(NOT IS_ABSOLUTE "${launch_screen}")
- message(FATAL_ERROR
- "Provided launch screen value should be an absolute path: '${launch_screen}'")
- endif()
-
- if(NOT EXISTS "${launch_screen}")
- message(FATAL_ERROR
- "Provided launch screen file does not exist: '${launch_screen}'")
- endif()
- endif()
-
- if(launch_screen AND NOT QT_NO_ADD_IOS_LAUNCH_SCREEN_TO_BUNDLE)
- get_filename_component(launch_screen_name "${launch_screen}" NAME)
-
- # Make a copy of the default launch screen template for this target and replace the
- # label inside the template with the target name.
- if(is_default_launch_screen)
- # Configure our default template and place it in the build dir.
- set(launch_screen_in_path "${launch_screen}")
-
- string(MAKE_C_IDENTIFIER "${target}" target_identifier)
- set(launch_screen_out_dir
- "${CMAKE_CURRENT_BINARY_DIR}/.qt/launch_screen_storyboards/${target_identifier}")
-
- set(launch_screen_out_path
- "${launch_screen_out_dir}/${launch_screen_name}")
-
- file(MAKE_DIRECTORY "${launch_screen_out_dir}")
-
- # Replaces the value in the default template.
- set(QT_IOS_LAUNCH_SCREEN_TEXT "${target}")
- configure_file(
- "${launch_screen_in_path}"
- "${launch_screen_out_path}"
- @ONLY
- )
-
- set(final_launch_screen_path "${launch_screen_out_path}")
- else()
- set(final_launch_screen_path "${launch_screen}")
- endif()
-
- # Add the launch screen storyboard file as a source file, otherwise CMake doesn't consider
- # it as a resource file and MACOSX_PACKAGE_LOCATION processing will be skipped.
- target_sources("${target}" PRIVATE "${final_launch_screen_path}")
-
- # Ensure Xcode compiles the storyboard file and installs the compiled storyboard .nib files
- # into the app bundle.
- # We use target_sources and the MACOSX_PACKAGE_LOCATION source file property for that
- # instead of the RESOURCE target property, becaues the latter could potentially end up
- # needlessly installing the source storyboard file.
- #
- # We can't rely on policy CMP0118 since user project controls it.
- set(scope_args)
- if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
- set(scope_args TARGET_DIRECTORY ${target})
- endif()
- set_source_files_properties("${final_launch_screen_path}" ${scope_args}
- PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
-
- # Save the launch screen name, so its value is added as an UILaunchStoryboardName entry
- # in the Qt generated Info.plist file.
- set_target_properties("${target}" PROPERTIES
- _qt_ios_launch_screen_name "${launch_screen_name}"
- _qt_ios_launch_screen_path "${final_launch_screen_path}")
- endif()
-endfunction()
-
-function(_qt_internal_find_ios_development_team_id out_var)
- get_property(team_id GLOBAL PROPERTY _qt_internal_ios_development_team_id)
- get_property(team_id_computed GLOBAL PROPERTY _qt_internal_ios_development_team_id_computed)
- if(team_id_computed)
- # Just in case if the value is non-empty but still booly FALSE.
- if(NOT team_id)
- set(team_id "")
- endif()
- set("${out_var}" "${team_id}" PARENT_SCOPE)
- return()
- endif()
-
- set_property(GLOBAL PROPERTY _qt_internal_ios_development_team_id_computed "TRUE")
-
- set(home_dir "$ENV{HOME}")
- set(xcode_preferences_path "${home_dir}/Library/Preferences/com.apple.dt.Xcode.plist")
-
- # Extract the first account name (email) from the user's Xcode preferences
- message(DEBUG "Trying to extract an Xcode development team id from '${xcode_preferences_path}'")
- execute_process(COMMAND "/usr/libexec/PlistBuddy"
- -x -c "print IDEProvisioningTeams" "${xcode_preferences_path}"
- OUTPUT_VARIABLE teams_xml
- ERROR_VARIABLE plist_error)
-
- # Parsing state.
- set(is_free "")
- set(current_team_id "")
- set(parsing_is_free FALSE)
- set(parsing_team_id FALSE)
- set(first_team_id "")
-
- # Parse the xml output and return the first encountered non-free team id. If no non-free team id
- # is found, return the first encountered free team id.
- # If no team is found, return an empty string.
- #
- # Example input:
- #<plist version="1.0">
- #<dict>
- # <key>marty@planet.local</key>
- # <array>
- # <dict>
- # <key>isFreeProvisioningTeam</key>
- # <false/>
- # <key>teamID</key>
- # <string>AAA</string>
- # ...
- # </dict>
- # <dict>
- # <key>isFreeProvisioningTeam</key>
- # <true/>
- # <key>teamID</key>
- # <string>BBB</string>
- # ...
- # </dict>
- # </array>
- #</dict>
- #</plist>
- if(teams_xml AND NOT plist_error)
- string(REPLACE "\n" ";" teams_xml_lines "${teams_xml}")
-
- foreach(xml_line ${teams_xml_lines})
- string(STRIP "${xml_line}" xml_line)
- if(xml_line STREQUAL "<dict>")
- # Clean any previously found values when a new team dict is matched.
- set(is_free "")
- set(current_team_id "")
-
- elseif(xml_line STREQUAL "<key>isFreeProvisioningTeam</key>")
- set(parsing_is_free TRUE)
-
- elseif(parsing_is_free)
- set(parsing_is_free FALSE)
-
- if(xml_line MATCHES "true")
- set(is_free TRUE)
- else()
- set(is_free FALSE)
- endif()
-
- elseif(xml_line STREQUAL "<key>teamID</key>")
- set(parsing_team_id TRUE)
-
- elseif(parsing_team_id)
- set(parsing_team_id FALSE)
- if(xml_line MATCHES "<string>([^<]+)</string>")
- set(current_team_id "${CMAKE_MATCH_1}")
- else()
- continue()
- endif()
-
- string(STRIP "${current_team_id}" current_team_id)
-
- # If this is the first team id we found so far, remember that, regardless if's free
- # or not.
- if(NOT first_team_id AND current_team_id)
- set(first_team_id "${current_team_id}")
- endif()
-
- # Break early if we found a non-free team id and use it, because we prefer
- # a non-free team for signing, just like qmake.
- if(NOT is_free AND current_team_id)
- set(first_team_id "${current_team_id}")
- break()
- endif()
- endif()
- endforeach()
- endif()
-
- if(NOT first_team_id)
- message(DEBUG "Failed to extract an Xcode development team id.")
- set("${out_var}" "" PARENT_SCOPE)
- else()
- message(DEBUG "Successfully extracted the first encountered Xcode development team id.")
- set_property(GLOBAL PROPERTY _qt_internal_ios_development_team_id "${first_team_id}")
- set("${out_var}" "${first_team_id}" PARENT_SCOPE)
- endif()
-endfunction()
-
-function(_qt_internal_get_ios_bundle_identifier_prefix out_var)
- get_property(prefix GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix)
- get_property(prefix_computed GLOBAL PROPERTY
- _qt_internal_ios_bundle_identifier_prefix_computed)
- if(prefix_computed)
- # Just in case if the value is non-empty but still booly FALSE.
- if(NOT prefix)
- set(prefix "")
- endif()
- set("${out_var}" "${prefix}" PARENT_SCOPE)
- return()
- endif()
-
- set_property(GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix_computed "TRUE")
-
- set(home_dir "$ENV{HOME}")
- set(xcode_preferences_path "${home_dir}/Library/Preferences/com.apple.dt.Xcode.plist")
-
- message(DEBUG "Trying to extract the default bundle identifier prefix from Xcode preferences.")
- execute_process(COMMAND "/usr/libexec/PlistBuddy"
- -c "print IDETemplateOptions:bundleIdentifierPrefix"
- "${xcode_preferences_path}"
- OUTPUT_VARIABLE prefix
- ERROR_VARIABLE prefix_error)
- if(prefix AND NOT prefix_error)
- message(DEBUG "Successfully extracted the default bundle identifier prefix.")
- string(STRIP "${prefix}" prefix)
- else()
- message(DEBUG "Failed to extract the default bundle identifier prefix.")
- endif()
-
- if(prefix AND NOT prefix_error)
- set_property(GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix "${prefix}")
- set("${out_var}" "${prefix}" PARENT_SCOPE)
- else()
- set("${out_var}" "" PARENT_SCOPE)
- endif()
-endfunction()
-
-function(_qt_internal_escape_rfc_1034_identifier value out_var)
- # According to https://datatracker.ietf.org/doc/html/rfc1034#section-3.5
- # we can only use letters, digits, dot (.) and hyphens (-).
- # Underscores are not allowed.
- string(REGEX REPLACE "[^A-Za-z0-9.]" "-" value "${value}")
-
- set("${out_var}" "${value}" PARENT_SCOPE)
-endfunction()
-
-function(_qt_internal_get_default_ios_bundle_identifier out_var)
- _qt_internal_get_ios_bundle_identifier_prefix(prefix)
- if(NOT prefix)
- set(prefix "com.yourcompany")
-
- # For a better out-of-the-box experience, try to create a unique prefix by appending
- # the sha1 of the team id, if one is found.
- _qt_internal_find_ios_development_team_id(team_id)
- if(team_id)
- string(SHA1 hash "${team_id}")
- string(SUBSTRING "${hash}" 0 8 infix)
- string(APPEND prefix ".${infix}")
- else()
- message(WARNING
- "No organization bundle identifier prefix could be retrieved from Xcode "
- "preferences. This can lead to code signing issues due to a non-unique bundle "
- "identifier. Please set up an organization prefix by creating a new project within "
- "Xcode, or consider providing a custom bundle identifier by specifying the "
- "XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER property."
- )
- endif()
- endif()
-
- # Escape the prefix according to rfc 1034, it's important for code-signing. If an invalid
- # identifier is used, calling xcodebuild on the command line says that no provisioning profile
- # could be found, with no additional error message. If one opens the generated project with
- # Xcode and clicks on 'Try again' to get a new profile, it shows a semi-useful error message
- # that the identifier is invalid.
- _qt_internal_escape_rfc_1034_identifier("${prefix}" prefix)
-
- set(identifier "${prefix}.\${PRODUCT_NAME:rfc1034identifier}")
- set("${out_var}" "${identifier}" PARENT_SCOPE)
-endfunction()
-
-function(_qt_internal_set_placeholder_apple_bundle_version target)
- # If user hasn't provided neither a bundle version nor a bundle short version string for the
- # app, set a placeholder value for both which will add them to the generated Info.plist file.
- # This is required so that the app launches in the simulator (but apparently not for running
- # on-device).
- get_target_property(bundle_version "${target}" MACOSX_BUNDLE_BUNDLE_VERSION)
- get_target_property(bundle_short_version "${target}" MACOSX_BUNDLE_SHORT_VERSION_STRING)
-
- if(NOT MACOSX_BUNDLE_BUNDLE_VERSION AND
- NOT MACOSX_BUNDLE_SHORT_VERSION_STRING AND
- NOT bundle_version AND
- NOT bundle_short_version AND
- NOT QT_NO_SET_XCODE_BUNDLE_VERSION
- )
- set(bundle_version "0.0.1")
- set(bundle_short_version "0.0.1")
- set_target_properties("${target}"
- PROPERTIES
- MACOSX_BUNDLE_BUNDLE_VERSION "${bundle_version}"
- MACOSX_BUNDLE_SHORT_VERSION_STRING "${bundle_short_version}"
- )
- endif()
-endfunction()
-
-function(_qt_internal_set_xcode_development_team_id target)
- # If user hasn't provided a development team id, try to find the first one specified
- # in the Xcode preferences.
- if(NOT CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM AND NOT QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID)
- get_target_property(existing_team_id "${target}" XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
- if(NOT existing_team_id)
- _qt_internal_find_ios_development_team_id(team_id)
- set_target_properties("${target}"
- PROPERTIES XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${team_id}")
- endif()
- endif()
-endfunction()
-
-function(_qt_internal_set_xcode_bundle_identifier target)
- # Skip all logic if requested.
- if(QT_NO_SET_XCODE_BUNDLE_IDENTIFIER)
- return()
- endif()
-
- # There are two fields to consider: the CFBundleIdentifier key (CFBI) to be written to
- # Info.plist
- # and the PRODUCT_BUNDLE_IDENTIFIER (PBI) property to set in the Xcode project.
- # The following logic enables the best out-of-the-box experience combined with maximum
- # customization.
- # 1) If values for both fields are not provided, assign ${PRODUCT_BUNDLE_IDENTIFIER} to CFBI
- # (which is expanded by xcodebuild at build time and will use the value of PBI) and
- # auto-compute a default PBI from Xcode's ${PRODUCT_NAME}.
- # 2) If CFBI is set and PBI isn't, use given CFBI and keep PBI empty.
- # 3) If PBI is set and CFBI isn't, assign ${PRODUCT_BUNDLE_IDENTIFIER} to CFBI and use
- # the given PBI.
- # 4) If both are set, use both given values.
- # TLDR:
- # cfbi pbi -> result_cfbi result_pbi
- # unset unset computed computed
- # set unset given_val unset
- # unset set computed given_val
- # set set given_val given_val
-
- get_target_property(existing_cfbi "${target}" MACOSX_BUNDLE_GUI_IDENTIFIER)
- if(NOT MACOSX_BUNDLE_GUI_IDENTIFIER AND NOT existing_cfbi)
- set(is_cfbi_given FALSE)
- else()
- set(is_cfbi_given TRUE)
- endif()
-
- if(NOT is_cfbi_given)
- set_target_properties("${target}"
- PROPERTIES
- MACOSX_BUNDLE_GUI_IDENTIFIER "\${PRODUCT_BUNDLE_IDENTIFIER}")
- endif()
-
- get_target_property(existing_pbi "${target}" XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER)
- if(NOT CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER AND NOT existing_pbi)
- set(is_pbi_given FALSE)
- else()
- set(is_pbi_given TRUE)
- endif()
-
- if(NOT is_pbi_given AND NOT is_cfbi_given)
- _qt_internal_get_default_ios_bundle_identifier(bundle_id)
- set_target_properties("${target}"
- PROPERTIES
- XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${bundle_id}")
- endif()
-endfunction()
-
-function(_qt_internal_set_xcode_targeted_device_family target)
- if(NOT CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY
- AND NOT QT_NO_SET_XCODE_TARGETED_DEVICE_FAMILY)
- get_target_property(existing_device_family
- "${target}" XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY)
- if(NOT existing_device_family)
- set(device_family_iphone_and_ipad "1,2")
- set_target_properties("${target}"
- PROPERTIES
- XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY
- "${device_family_iphone_and_ipad}")
- endif()
- endif()
-endfunction()
-
-function(_qt_internal_set_xcode_code_sign_style target)
- if(NOT CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE
- AND NOT QT_NO_SET_XCODE_CODE_SIGN_STYLE)
- get_target_property(existing_code_style
- "${target}" XCODE_ATTRIBUTE_CODE_SIGN_STYLE)
- if(NOT existing_code_style)
- set(existing_code_style "Automatic")
- set_target_properties("${target}"
- PROPERTIES
- XCODE_ATTRIBUTE_CODE_SIGN_STYLE
- "${existing_code_style}")
- endif()
- endif()
-endfunction()
-
-function(_qt_internal_set_xcode_bundle_display_name target)
- # We want the value of CFBundleDisplayName to be ${PRODUCT_NAME}, but we can't put that
- # into the Info.plist.in template file directly, because the implicit configure_file(Info.plist)
- # done by CMake is not using the @ONLY option, so CMake would treat the assignment as
- # variable expansion. Escaping using backslashes does not help.
- # Work around it by assigning the dollar char to a separate cache var, and expand it, so that
- # the final value in the file will be ${PRODUCT_NAME}, to be evaluated at build time by Xcode.
- set(QT_INTERNAL_DOLLAR_VAR "$" CACHE STRING "")
-endfunction()
-
-function(_qt_internal_generate_ios_info_plist target)
- # If the project already specifies a custom file, we don't override it.
- get_target_property(existing_plist "${target}" MACOSX_BUNDLE_INFO_PLIST)
- if(existing_plist)
- return()
- endif()
-
- set(info_plist_in "${__qt_internal_cmake_ios_support_files_path}/Info.plist.app.in")
-
- string(MAKE_C_IDENTIFIER "${target}" target_identifier)
- set(info_plist_out_dir
- "${CMAKE_CURRENT_BINARY_DIR}/.qt/info_plist/${target_identifier}")
- set(info_plist_out "${info_plist_out_dir}/Info.plist")
-
- # Check if we need to specify a custom launch screen storyboard entry.
- get_target_property(launch_screen_name "${target}" _qt_ios_launch_screen_name)
- if(launch_screen_name)
- set(qt_ios_launch_screen_plist_entry "${launch_screen_name}")
- endif()
-
- # Call configure_file to substitute Qt-specific @FOO@ values, not ${FOO} values.
- #
- # The output file will be another template file to be fed to CMake via the
- # MACOSX_BUNDLE_INFO_PLIST property. CMake will then call configure_file on it to provide
- # content for regular entries like CFBundleName, etc.
- #
- # We require this extra configure_file call so we can create unique Info.plist files for each
- # target in a project, while also providing a way to add Qt specific entries that CMake
- # does not support out of the box (e.g. a launch screen name).
- configure_file(
- "${info_plist_in}"
- "${info_plist_out}"
- @ONLY
- )
-
- set_target_properties("${target}" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${info_plist_out}")
-endfunction()
-
-function(_qt_internal_set_xcode_bitcode_enablement target)
- if(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE
- OR QT_NO_SET_XCODE_ENABLE_BITCODE)
- return()
- endif()
-
- get_target_property(existing_bitcode_enablement
- "${target}" XCODE_ATTRIBUTE_ENABLE_BITCODE)
- if(NOT existing_bitcode_enablement MATCHES "-NOTFOUND")
- return()
- endif()
-
- # Disable bitcode to match Xcode 14's new default
- set_target_properties("${target}"
- PROPERTIES
- XCODE_ATTRIBUTE_ENABLE_BITCODE
- "NO")
-endfunction()
-
-function(_qt_internal_finalize_ios_app target)
- _qt_internal_set_xcode_development_team_id("${target}")
- _qt_internal_set_xcode_bundle_identifier("${target}")
- _qt_internal_set_xcode_targeted_device_family("${target}")
- _qt_internal_set_xcode_code_sign_style("${target}")
- _qt_internal_set_xcode_bundle_display_name("${target}")
- _qt_internal_set_xcode_bitcode_enablement("${target}")
-
- _qt_internal_handle_ios_launch_screen("${target}")
- _qt_internal_set_placeholder_apple_bundle_version("${target}")
- _qt_internal_generate_ios_info_plist("${target}")
-endfunction()
-
-function(_qt_internal_finalize_macos_app target)
- get_target_property(is_bundle ${target} MACOSX_BUNDLE)
- if(NOT is_bundle)
- return()
- endif()
-
- # Make sure the install rpath has at least the minimum needed if the app
- # has any non-static frameworks. We can't rigorously know if the app will
- # have any, even with a static Qt, so always add this. If there are no
- # frameworks, it won't do any harm.
- get_property(install_rpath TARGET ${target} PROPERTY INSTALL_RPATH)
- list(APPEND install_rpath "@executable_path/../Frameworks")
- list(REMOVE_DUPLICATES install_rpath)
- set_property(TARGET ${target} PROPERTY INSTALL_RPATH "${install_rpath}")
-endfunction()
-
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
function(qt_add_executable)
qt6_add_executable(${ARGV})
@@ -2225,13 +1709,20 @@ function(_qt_internal_process_resource target resourceName)
endif()
get_source_file_property(
target_dependency ${file} ${scope_args} _qt_resource_target_dependency)
- if (NOT target_dependency)
- list(APPEND resource_dependencies ${file})
- else()
- if (NOT TARGET ${target_dependency})
- message(FATAL_ERROR "Target dependency on resource file ${file} is not a cmake target.")
+
+ # The target dependency code path does not take care of rebuilds when ${file}
+ # is touched. Limit its usage to the Xcode generator to avoid the Xcode common
+ # dependency issue.
+ # TODO: Figure out how to avoid the issue on Xcode, while also enabling proper
+ # dependency tracking when ${file} is touched.
+ if(target_dependency AND CMAKE_GENERATOR STREQUAL "Xcode")
+ if(NOT TARGET ${target_dependency})
+ message(FATAL_ERROR
+ "Target dependency on resource file ${file} is not a cmake target.")
endif()
list(APPEND resource_dependencies ${target_dependency})
+ else()
+ list(APPEND resource_dependencies ${file})
endif()
_qt_internal_expose_source_file_to_ide(${target} "${file}")
endforeach()
@@ -2351,6 +1842,10 @@ function(qt6_add_plugin target)
cmake_parse_arguments(PARSE_ARGV 1 arg "${opt_args}" "${single_args}" "${multi_args}")
+ if (arg_UNPARSED_ARGUMENTS)
+ message(AUTHOR_WARNING "Unexpected arguments: ${arg_UNPARSED_ARGUMENTS}. If these are source files, consider using target_sources() instead.")
+ endif()
+
# Handle the inconsistent CLASSNAME/CLASS_NAME keyword naming between commands
if(arg_CLASSNAME)
if(arg_CLASS_NAME AND NOT arg_CLASSNAME STREQUAL arg_CLASS_NAME)
@@ -2633,30 +2128,6 @@ function(_qt_internal_apply_strict_cpp target)
endif()
endfunction()
-# Wraps a tool command with a script that contains the necessary environment for the tool to run
-# correctly.
-# _qt_internal_wrap_tool_command(var <SET|APPEND> <command> [args...])
-# Arguments:
-# APPEND Selects the 'append' mode for the out_variable argument.
-# SET Selects the 'set' mode for the out_variable argument.
-function(_qt_internal_wrap_tool_command out_variable action)
- set(append FALSE)
- if(action STREQUAL "APPEND")
- set(append TRUE)
- elseif(NOT action STREQUAL "SET")
- message(FATAL_ERROR "Invalid action specified ${action}. Supported actions: SET, APPEND")
- endif()
-
- set(cmd COMMAND ${QT_TOOL_COMMAND_WRAPPER_PATH} ${ARGN})
-
- if(append)
- list(APPEND ${out_variable} ${cmd})
- else()
- set(${out_variable} ${cmd})
- endif()
- set(${out_variable} "${${out_variable}}" PARENT_SCOPE)
-endfunction()
-
# Copies properties of the dependency to the target.
# Arguments:
# PROPERTIES list of properties to copy. If not specified the following properties are copied
diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake
index 8f9720653b..8eb137d3ef 100644
--- a/src/corelib/Qt6WasmMacros.cmake
+++ b/src/corelib/Qt6WasmMacros.cmake
@@ -1,22 +1,39 @@
# Copy in Qt HTML/JS launch files for apps.
function(_qt_internal_wasm_add_target_helpers target)
+
+ _qt_test_emscripten_version()
get_target_property(targetType "${target}" TYPE)
if("${targetType}" STREQUAL "EXECUTABLE")
- set(APPNAME ${target})
-
if(QT6_INSTALL_PREFIX)
set(WASM_BUILD_DIR "${QT6_INSTALL_PREFIX}")
elseif(QT_BUILD_DIR)
set(WASM_BUILD_DIR "${QT_BUILD_DIR}")
endif()
+ get_target_property(output_name ${target} OUTPUT_NAME)
+ if(output_name)
+ set(_target_output_name "${output_name}")
+ else()
+ set(_target_output_name "${target}")
+ endif()
+
+ set(APPNAME ${_target_output_name})
+
+ get_target_property(target_output_directory ${target} RUNTIME_OUTPUT_DIRECTORY)
+
+ if(target_output_directory)
+ set(_target_directory "${target_output_directory}")
+ else()
+ set(_target_directory "${CMAKE_CURRENT_BINARY_DIR}")
+ endif()
+
configure_file("${WASM_BUILD_DIR}/plugins/platforms/wasm_shell.html"
- "${target}.html")
+ "${_target_directory}/${_target_output_name}.html")
configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtloader.js"
- qtloader.js COPYONLY)
+ ${_target_directory}/qtloader.js COPYONLY)
configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg"
- qtlogo.svg COPYONLY)
+ ${_target_directory}/qtlogo.svg COPYONLY)
if(QT_FEATURE_thread)
set(POOL_SIZE 4)
@@ -57,3 +74,21 @@ function(_qt_internal_wasm_add_target_helpers target)
endif()
endfunction()
+function(_qt_internal_add_wasm_extra_exported_methods target)
+ get_target_property(wasm_extra_exported_methods "${target}" QT_WASM_EXTRA_EXPORTED_METHODS)
+
+ if(NOT wasm_extra_exported_methods)
+ set(wasm_extra_exported_methods ${QT_WASM_EXTRA_EXPORTED_METHODS})
+ endif()
+
+ if(wasm_extra_exported_methods)
+ target_link_options("${target}" PRIVATE
+ "SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,${wasm_extra_exported_methods}"
+ )
+ else()
+ # an errant dangling comma will break this
+ target_link_options("${target}" PRIVATE
+ "SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16"
+ )
+ endif()
+endfunction()
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index d57ce4ef5f..46ed60d6d1 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -283,7 +283,7 @@ void QUnifiedTimer::updateAnimationTimers()
QScopedValueRollback<bool> guard(insideTick, true);
if (profilerCallback)
profilerCallback(delta);
- for (currentAnimationIdx = 0; currentAnimationIdx < animationTimers.count(); ++currentAnimationIdx) {
+ for (currentAnimationIdx = 0; currentAnimationIdx < animationTimers.size(); ++currentAnimationIdx) {
QAbstractAnimationTimer *animation = animationTimers.at(currentAnimationIdx);
animation->updateAnimationsTime(delta);
}
@@ -294,7 +294,7 @@ void QUnifiedTimer::updateAnimationTimers()
int QUnifiedTimer::runningAnimationCount()
{
int count = 0;
- for (int i = 0; i < animationTimers.count(); ++i)
+ for (int i = 0; i < animationTimers.size(); ++i)
count += animationTimers.at(i)->runningAnimationCount();
return count;
}
@@ -309,7 +309,7 @@ void QUnifiedTimer::localRestart()
if (insideRestart)
return;
- if (!pausedAnimationTimers.isEmpty() && (animationTimers.count() + animationTimersToStart.count() == pausedAnimationTimers.count())) {
+ if (!pausedAnimationTimers.isEmpty() && (animationTimers.size() + animationTimersToStart.size() == pausedAnimationTimers.size())) {
driver->stop();
int closestTimeToFinish = closestPausedAnimationTimerTimeToFinish();
// use a precise timer if the pause will be short
@@ -327,7 +327,7 @@ void QUnifiedTimer::restart()
{
{
QScopedValueRollback<bool> guard(insideRestart, true);
- for (int i = 0; i < animationTimers.count(); ++i)
+ for (int i = 0; i < animationTimers.size(); ++i)
animationTimers.at(i)->restartAnimationTimer();
}
@@ -568,7 +568,7 @@ void QAnimationTimer::updateAnimationsTime(qint64 delta)
//when the CPU load is high
if (delta) {
QScopedValueRollback<bool> guard(insideTick, true);
- for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) {
+ for (currentAnimationIdx = 0; currentAnimationIdx < animations.size(); ++currentAnimationIdx) {
QAbstractAnimation *animation = animations.at(currentAnimationIdx);
int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime
+ (animation->direction() == QAbstractAnimation::Forward ? delta : -delta);
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index 2b08ef7756..5be59543c8 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -247,7 +247,7 @@ public:
void updateAnimationsTime(qint64 delta) override;
//useful for profiling/debugging
- int runningAnimationCount() override { return animations.count(); }
+ int runningAnimationCount() override { return animations.size(); }
private Q_SLOTS:
void startAnimations();
diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp
index 5502942302..e8ffd99dcb 100644
--- a/src/corelib/animation/qanimationgroup.cpp
+++ b/src/corelib/animation/qanimationgroup.cpp
@@ -138,7 +138,7 @@ int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
void QAnimationGroup::addAnimation(QAbstractAnimation *animation)
{
Q_D(QAnimationGroup);
- insertAnimation(d->animations.count(), animation);
+ insertAnimation(d->animations.size(), animation);
}
/*!
@@ -261,7 +261,7 @@ 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) {
+ for (int i = animationsCopy.size() - 1; i >= 0; --i) {
QAbstractAnimation *animation = animationsCopy.at(i);
animation->setParent(nullptr);
QAbstractAnimationPrivate::get(animation)->group = nullptr;
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 109358b389..985371d30f 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -22,6 +22,10 @@
\snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \note You can also control an animation's lifespan by choosing a
+ \l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting the
+ animation.
+
The property name and the QObject instance of which property
should be animated are passed to the constructor. You can then
specify the start and end value of the property. The procedure is
diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp
index 25d6d1de37..8e99d9cee0 100644
--- a/src/corelib/animation/qsequentialanimationgroup.cpp
+++ b/src/corelib/animation/qsequentialanimationgroup.cpp
@@ -172,7 +172,7 @@ void QSequentialAnimationGroupPrivate::rewindForwards(const AnimationIndex &newA
// we need to force activation because setCurrentAnimation will have no effect
activateCurrentAnimation();
else
- setCurrentAnimation(animations.count() - 1, true);
+ setCurrentAnimation(animations.size() - 1, true);
}
// and now we need to fast rewind from the current position to
@@ -396,7 +396,7 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter
// currentAnimation.removeBindingUnlessInWrapper()
// is not necessary here, since it is read only
- index = qMin(index, animations.count() - 1);
+ index = qMin(index, animations.size() - 1);
if (index == -1) {
Q_ASSERT(animations.isEmpty());
@@ -517,7 +517,7 @@ void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnim
disconnectUncontrolledAnimation(currentAnimation);
- if (index < animations.count())
+ if (index < animations.size())
setCurrentAnimation(index); //let's try to take the next one
else if (index > 0)
setCurrentAnimation(index - 1);
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index cd9a01a138..cf84200f2a 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -156,7 +156,7 @@ void QVariantAnimationPrivate::convertValues(int t)
{
auto type = QMetaType(t);
//this ensures that all the keyValues are of type t
- for (int i = 0; i < keyValues.count(); ++i) {
+ for (int i = 0; i < keyValues.size(); ++i) {
QVariantAnimation::KeyValue &pair = keyValues[i];
pair.second.convert(type);
}
@@ -190,7 +190,7 @@ void QVariantAnimationPrivate::updateInterpolator()
void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
{
// can't interpolate if we don't have at least 2 values
- if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
+ if ((keyValues.size() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
return;
const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
@@ -207,7 +207,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
animationValueLessThan);
if (it == keyValues.constBegin()) {
//the item pointed to by it is the start element in the range
- if (it->first == 0 && keyValues.count() > 1) {
+ if (it->first == 0 && keyValues.size() > 1) {
currentInterval.start = *it;
currentInterval.end = *(it+1);
} else {
@@ -216,7 +216,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
}
} else if (it == keyValues.constEnd()) {
--it; //position the iterator on the last item
- if (it->first == 1 && keyValues.count() > 1) {
+ if (it->first == 1 && keyValues.size() > 1) {
//we have an end value (item with progress = 1)
currentInterval.start = *(it-1);
currentInterval.end = *it;
@@ -405,7 +405,7 @@ void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator fun
// to continue causes the app to crash on exit with a SEGV
if (interpolators) {
const auto locker = qt_scoped_lock(registeredInterpolatorsMutex);
- if (interpolationType >= interpolators->count())
+ if (interpolationType >= interpolators->size())
interpolators->resize(interpolationType + 1);
interpolators->replace(interpolationType, func);
}
@@ -423,7 +423,7 @@ QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int in
QInterpolatorVector *interpolators = registeredInterpolators();
const auto locker = qt_scoped_lock(registeredInterpolatorsMutex);
QVariantAnimation::Interpolator ret = nullptr;
- if (interpolationType < interpolators->count()) {
+ if (interpolationType < interpolators->size()) {
ret = interpolators->at(interpolationType);
if (ret) return ret;
}
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index dec623d3ff..adf59111dd 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -173,24 +173,6 @@ QCalendar::QCalendar(QLatin1StringView name)
#include "qcollator.h" // inline function compare(ptr, n, ptr, n) (for MSVC)
-#if QT_CONFIG(future)
-
-#include "qfutureinterface.h"
-#include "private/qfutureinterface_p.h"
-
-void QFutureInterfaceBase::cleanContinuation()
-{
- if (!d)
- return;
-
- // This was called when the associated QPromise was being destroyed,
- // but isn't used anymore.
- QMutexLocker lock(&d->continuationMutex);
- d->continuation = nullptr;
-}
-
-#endif // QT_CONFIG(future)
-
#include "qhashfunctions.h"
size_t qHash(const QByteArray &key, size_t seed) noexcept
@@ -212,6 +194,8 @@ void QObject::setObjectName(const QString &name)
#include "qlocale.h" // uses QT_CORE_INLINE_SINCE
+#if QT_CONFIG(settings)
+
#include "qsettings.h"
void QSettings::beginGroup(const QString &prefix)
@@ -254,6 +238,7 @@ QVariant QSettings::value(const QString &key) const
return value(qToAnyStringViewIgnoringNull(key));
}
+#endif // QT_CONFIG(settings)
#include "qversionnumber.h"
diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake
index 183decb530..1ce685170a 100644
--- a/src/corelib/configure.cmake
+++ b/src/corelib/configure.cmake
@@ -743,7 +743,7 @@ qt_feature("xmlstream" PUBLIC
LABEL "XML Streaming APIs"
PURPOSE "Provides a simple streaming API for XML."
)
-qt_feature("cpp-winrt" PRIVATE
+qt_feature("cpp-winrt" PRIVATE PUBLIC
LABEL "cpp/winrt base"
PURPOSE "basic cpp/winrt language projection support"
CONDITION WIN32 AND TEST_cpp_winrt
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp
index 51d369d1d5..680a099f68 100644
--- a/src/corelib/doc/snippets/code/doc_src_containers.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp
@@ -16,10 +16,30 @@ private:
};
//! [0]
+//! [range_for]
+QList<QString> list = {"A", "B", "C", "D"};
+for (const auto &item : list) {
+ ...
+}
+//! [range_for]
+
+//! [range_for_as_const]
+QList<QString> list = {"A", "B", "C", "D"};
+for (const auto &item : std::as_const(list)) {
+ ...
+}
+//! [range_for_as_const]
+
+//! [index]
+QList<QString> list = {"A", "B", "C", "D"};
+for (qsizetype i = 0; i < list.size(); ++i) {
+ const auto &item = list.at(i);
+ ...
+}
+//! [index]
//! [1]
-QList<QString> list;
-list << "A" << "B" << "C" << "D";
+QList<QString> list = {"A", "B", "C", "D"};
QListIterator<QString> i(list);
while (i.hasNext())
@@ -71,11 +91,12 @@ while (i.hasNext())
//! [7]
-QMap<QString, QString> map;
-map.insert("Paris", "France");
-map.insert("Guatemala City", "Guatemala");
-map.insert("Mexico City", "Mexico");
-map.insert("Moscow", "Russia");
+QMap<QString, QString> map = {
+ {"Paris", "France"},
+ {"Guatemala City", "Guatemala"},
+ {"Mexico City", "Mexico"},
+ {"Moscow", "Russia"}
+};
...
QMutableMapIterator<QString, QString> i(map);
@@ -106,28 +127,23 @@ while (i.findNext(widget))
//! [10]
-QList<QString> list;
-list << "A" << "B" << "C" << "D";
+QList<QString> list = {"A", "B", "C", "D"};
-QList<QString>::iterator i;
-for (i = list.begin(); i != list.end(); ++i)
+for (auto i = list.begin(), end = list.end(); i != end; ++i)
*i = (*i).toLower();
//! [10]
//! [11]
-QList<QString> list;
-list << "A" << "B" << "C" << "D";
+QList<QString> list = {"A", "B", "C", "D"};
-QList<QString>::reverse_iterator i;
-for (i = list.rbegin(); i != list.rend(); ++i)
+for (auto i = list.rbegin(), rend = list.rend(); i != rend; ++i)
*i = i->toLower();
//! [11]
//! [12]
-QList<QString>::const_iterator i;
-for (i = list.constBegin(); i != list.constEnd(); ++i)
+for (auto i = list.cbegin(), end = list.cend(); i != end; ++i)
qDebug() << *i;
//! [12]
@@ -135,8 +151,7 @@ for (i = list.constBegin(); i != list.constEnd(); ++i)
//! [13]
QMap<int, int> map;
...
-QMap<int, int>::const_iterator i;
-for (i = map.constBegin(); i != map.constEnd(); ++i)
+for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
qDebug() << i.key() << ':' << i.value();
//! [13]
@@ -144,13 +159,11 @@ for (i = map.constBegin(); i != map.constEnd(); ++i)
//! [14]
// RIGHT
const QList<int> sizes = splitter->sizes();
-QList<int>::const_iterator i;
-for (i = sizes.begin(); i != sizes.end(); ++i)
+for (auto i = sizes.begin(), end = sizes.end(); i != end; ++i)
...
// WRONG
-QList<int>::const_iterator i;
-for (i = splitter->sizes().begin();
+for (auto i = splitter->sizes().begin();
i != splitter->sizes().end(); ++i)
...
//! [14]
@@ -234,9 +247,9 @@ target_compile_definitions(my_app PRIVATE QT_NO_KEYWORDS)
QString onlyLetters(const QString &in)
{
QString out;
- for (int j = 0; j < in.size(); ++j) {
- if (in[j].isLetter())
- out += in[j];
+ for (qsizetype j = 0; j < in.size(); ++j) {
+ if (in.at(j).isLetter())
+ out += in.at(j);
}
return out;
}
@@ -273,15 +286,15 @@ int j = *i; // Undefined behavior!
//! [24]
//! [25]
-QList<int> list { 1, 2, 3, 4, 4, 5 };
-QSet<int> set(list.begin(), list.end());
+QList<int> list = {1, 2, 3, 4, 4, 5};
+QSet<int> set(list.cbegin(), list.cend());
/*
Will generate a QSet containing 1, 2, 3, 4, 5.
*/
//! [25]
//! [26]
-QList<int> list { 2, 3, 1 };
+QList<int> list = {2, 3, 1};
std::sort(list.begin(), list.end());
/*
diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.pro b/src/corelib/doc/snippets/code/doc_src_qplugin.pro
deleted file mode 100644
index 52fb9e3163..0000000000
--- a/src/corelib/doc/snippets/code/doc_src_qplugin.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-#! [3]
-TEMPLATE = app
-QTPLUGIN += qjpeg qgif # image formats
-#! [3]
diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
index e50581a2c8..f8b74cd542 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
@@ -3,10 +3,94 @@
//! [0]
- QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
- animation->setDuration(10000);
- animation->setStartValue(QRect(0, 0, 100, 30));
- animation->setEndValue(QRect(250, 250, 100, 30));
+#include <QApplication>
+#include <QPushButton>
+#include <QPropertyAnimation>
+//! [1]
+class MyButtonWidget : public QWidget
+{
+public:
+ MyButtonWidget(QWidget *parent = nullptr);
+};
- animation->start();
+MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
+{
+ QPushButton *button = new QPushButton(tr("Animated Button"), this);
+ QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
+ anim->setDuration(10000);
+ anim->setStartValue(QPoint(0, 0));
+ anim->setEndValue(QPoint(100, 250));
+ anim->start();
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MyButtonWidget buttonAnimWidget;
+ buttonAnimWidget.resize(QSize(800, 600));
+ buttonAnimWidget.show();
+ return a.exec();
+}
+//! [1]
//! [0]
+
+
+//! [easing-curve]
+MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
+{
+ QPushButton *button = new QPushButton(tr("Animated Button"), this);
+ QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
+ anim->setDuration(10000);
+ anim->setStartValue(QPoint(0, 0));
+ anim->setEndValue(QPoint(100, 250));
+ anim->setEasingCurve(QEasingCurve::OutBounce);
+ anim->start();
+}
+//! [easing-curve]
+
+
+//! [animation-group1]
+MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
+{
+ QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
+ QPushButton *clyde = new QPushButton(tr("Clyde"), this);
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
+ anim1->setDuration(3000);
+ anim1->setStartValue(QPoint(0, 0));
+ anim1->setEndValue(QPoint(100, 250));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
+ anim2->setDuration(3000);
+ anim2->setStartValue(QPoint(100, 250));
+ anim2->setEndValue(QPoint(500, 500));
+
+ QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup;
+ parallelAnim->addAnimation(anim1);
+ parallelAnim->addAnimation(anim2);
+ parallelAnim->start();
+}
+//! [animation-group1]
+
+//! [animation-group2]
+MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
+{
+ QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
+ QPushButton *clyde = new QPushButton(tr("Clyde"), this);
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
+ anim1->setDuration(3000);
+ anim1->setStartValue(QPoint(0, 0));
+ anim1->setEndValue(QPoint(100, 250));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
+ anim2->setDuration(3000);
+ anim2->setStartValue(QPoint(0, 0));
+ anim2->setEndValue(QPoint(200, 250));
+
+ QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup;
+ sequenceAnim->addAnimation(anim1);
+ sequenceAnim->addAnimation(anim2);
+ sequenceAnim->start();
+}
+//! [animation-group2]
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index ff5f48b914..1786408c29 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -708,7 +708,7 @@ bool readConfiguration(const QFile &file)
QString s = ...;
for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
process(ch);
- for (QChar ch : qAsConst(s)) // ok, no detach attempt
+ for (QChar ch : std::as_const(s)) // ok, no detach attempt
process(ch);
//! [as-const-0]
@@ -724,12 +724,12 @@ bool readConfiguration(const QFile &file)
//! [as-const-2]
//! [as-const-3]
- for (QChar ch : qAsConst(funcReturningQString()))
+ for (QChar ch : std::as_const(funcReturningQString()))
process(ch); // ERROR: ch is copied from deleted memory
//! [as-const-3]
//! [as-const-4]
- for (QChar ch : qAsConst(funcReturningQString()))
+ for (QChar ch : std::as_const(funcReturningQString()))
process(ch); // ERROR: ch is copied from deleted memory
//! [as-const-4]
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
index 62ecc58a80..f002ea6fd5 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
@@ -1,6 +1,14 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [constructor-url-reference]
+QUrl url("example.com");
+//! [constructor-url-reference]
+
+//! [constructor-url]
+QUrl url("https://example.com");
+//! [constructor-url]
+
//! [0]
QUrl url("http://www.example.com/List of holidays.xml");
// url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml"
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
index b66951357d..a213ccbca6 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
@@ -35,12 +35,12 @@ MyStruct s2 = var.value<MyStruct>();
//! [3]
-int id = QMetaType::type("MyClass");
-if (id != QMetaType::UnknownType) {
- void *myClassPtr = QMetaType::create(id);
+QMetaType type = QMetaType::fromName("MyClass");
+if (type.isValid()) {
+ void *myClassPtr = type.create();
...
- QMetaType::destroy(id, myClassPtr);
- myClassPtr = 0;
+ type.destroy(myClassPtr);
+ myClassPtr = nullptr;
}
//! [3]
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
index f4cc826e6f..c2b55c9684 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
@@ -144,7 +144,7 @@ public:
Q_D(MyClass);
d->clients.push_back(c);
// notify that the value could have changed
- d->hasClientsData.markDirty();
+ d->hasClientsData.notify();
}
private:
Q_DECLARE_PRIVATE(MyClass)
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
index 7dfd17a1f1..5edcaae755 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
@@ -8,7 +8,7 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QTimer::singleShot(600000, &app, SLOT(quit()));
+ QTimer::singleShot(600000, &app, QCoreApplication::quit);
...
return app.exec();
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp
index e56cb4cdc7..b5d56054c6 100644
--- a/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_text_qstring.cpp
@@ -30,6 +30,9 @@ if (str == QString("auto") || str == QString("extern")
}
//! [4]
+//! [4bis]
+str.append("Hello ").append("World");
+//! [4bis]
//! [5]
if (str == "auto"_L1
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp
index 6b04d23b97..10e6eb6276 100644
--- a/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_text_qstringiterator.cpp
@@ -16,7 +16,7 @@ QStringIterator i(string); // implicitly converted to QStringView
//! [1]
while (i.hasNext())
- uint c = i.next();
+ char32_t c = i.next();
//! [1]
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index f1be49c1d4..b7e56c5ec3 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -297,11 +297,11 @@ inline size_t qHash(const std::unordered_set<int> &key, size_t seed = 0)
//! [31]
//! [32]
-size_t qHash(K key);
-size_t qHash(const K &key);
-
size_t qHash(K key, size_t seed);
size_t qHash(const K &key, size_t seed);
+
+size_t qHash(K key); // deprecated, do not use
+size_t qHash(const K &key); // deprecated, do not use
//! [32]
//! [33]
diff --git a/src/corelib/doc/snippets/qstringlist/main.cpp b/src/corelib/doc/snippets/qstringlist/main.cpp
index fa3540d8ce..d2175aafb5 100644
--- a/src/corelib/doc/snippets/qstringlist/main.cpp
+++ b/src/corelib/doc/snippets/qstringlist/main.cpp
@@ -22,24 +22,6 @@ Widget::Widget(QWidget *parent)
fonts << "Courier" << "Verdana";
//! [0b]
-//! [1]
- for (int i = 0; i < fonts.size(); ++i)
- cout << fonts.at(i).toLocal8Bit().constData() << Qt::endl;
-//! [1]
-
-//! [2]
- QStringListIterator javaStyleIterator(fonts);
- while (javaStyleIterator.hasNext())
- cout << javaStyleIterator.next().toLocal8Bit().constData() << Qt::endl;
-//! [2]
-
-//! [3]
- QStringList::const_iterator constIterator;
- for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();
- ++constIterator)
- cout << (*constIterator).toLocal8Bit().constData() << Qt::endl;
-//! [3]
-
//! [4]
QString str = fonts.join(", ");
// str == "Arial, Helvetica, Times, Courier"
diff --git a/src/corelib/doc/src/animation.qdoc b/src/corelib/doc/src/animation.qdoc
index e09300010a..28f88c907a 100644
--- a/src/corelib/doc/src/animation.qdoc
+++ b/src/corelib/doc/src/animation.qdoc
@@ -22,153 +22,134 @@
\keyword Animation
- The animation framework aims to provide an easy way for creating animated
- and smooth GUIs. By animating Qt properties, the framework provides great
- freedom for animating widgets and other \l{QObject}s. The framework can
- also be used with the Graphics View framework. Many of the concepts
- available in the animation framework are also available in \l{Qt Quick},
- where it offers a declarative way of defining animations. Much of the
- knowledge acquired about the animation framework can be applied to
- \l{Qt Quick}.
-
- In this overview, we explain the basics of its architecture. We
- also show examples of the most common techniques that the
- framework allows for animating \l{QObject}s and graphics items.
+ The animation framework provides an easy way to animate your GUI elements.
+ It enables you to animate a Qt property value of a widget or QObject.
+ Most of the features offered by the framework are also available in
+ \l{Qt Quick}, where it's possible to define animations in a declarative way.
+
+ This overview explains the framework's architecture, with examples that
+ demonstrate the common techniques used for animating QObject and
+ GUI elements.
\tableofcontents
- \section1 The Animation Architecture
+ \section1 The Animation architecture
- We will in this section take a high-level look at the animation
- framework's architecture and how it is used to animate Qt
- properties. The following diagram shows the most important classes
- in the animation framework.
+ The following diagram shows the most important classes provided by the
+ framework:
\image animations-architecture.png
- The animation framework foundation consists of the base class
- QAbstractAnimation, and its two subclasses QVariantAnimation and
- QAnimationGroup. QAbstractAnimation is the ancestor of all
- animations. It represents basic properties that are common for all
- animations in the framework; notably, the ability to start, stop,
- and pause an animation. It is also receives the time change
- notifications.
-
- The animation framework further provides the QPropertyAnimation
- class, which inherits QVariantAnimation and performs animation of
- a Qt property, which is part of Qt's \l{Meta-Object
- System}{meta-object system}. The class performs an interpolation
- over the property using an easing curve. So when you want to
- animate a value, you can declare it as a property and make your
- class a QObject. Note that this gives us great freedom in
- animating already existing widgets and other \l{QObject}s.
+ It includes the QAbstractAnimation class, which provides the
+ necessary foundation for animations. This class defines the
+ generic properties for all animations supported by the framework.
+ For example, the ability to start, stop, and pause an animation. The
+ class also receives the time change notifications.
+
+ The framework further provides the QVariantAnimation and
+ QAnimationGroup classes, which build on their base case, QAbstractAnimation.
+ Next in the hierarchy is QPropertyAnimation, which is derived from
+ QVariantAnmiation, and it lets you animate a Qt property of a widget or
+ QObject. The class performs interpolation on the property value using an
+ easing curve. With these in place, you just need a QObject class with a
+ Qt property value that you can animate.
+
+ \note It is required that the target object you are animating is a QObject
+ or its subclass. This is necessary as the animation framework depends on the
+ \l{Meta-Object System}{meta-object system} for all the information about the
+ object it is animating.
Complex animations can be constructed by building a tree structure
- of \l{QAbstractAnimation}s. The tree is built by using
- \l{QAnimationGroup}s, which function as containers for other
- animations. Note also that the groups are subclasses of
- QAbstractAnimation, so groups can themselves contain other groups.
+ of \l{QAbstractAnimation}s, where the tree is a QAnimationGroup that
+ contains other animations. These animation groups can also contain
+ subgroups representing different groups or animations, such as
+ QParallelAnimationGroup and QSequentialAnimationGroup.
- Behind the scenes, the animations are controlled by a global
- timer, which sends \l{QAbstractAnimation::updateCurrentTime()}{updates} to
- all animations that are playing.
+ Behind the scenes, all animations are controlled by a global
+ timer, which sends \l{QAbstractAnimation::updateCurrentTime()}{updates} about
+ all animations that are running.
- For detailed descriptions of the classes' function and roles in
- the framework, please look up their class descriptions.
+ For detailed information of these individual classes' and their roles in
+ the framework, refer to their documentation.
- \section1 Classes in the Animation Framework
+ \section1 Classes offered by the framework
- These classes provide a framework for creating both simple and complex
- animations.
+ These classes provide the necessary infrastructure to create both simple and
+ complex animations.
\annotatedlist animation
- \section1 Animating Qt Properties
+ \section1 Animating Qt properties
- As mentioned in the previous section, the QPropertyAnimation class can
- interpolate over Qt properties. It is often this class that should be used
- for animation of values; in fact, its superclass, QVariantAnimation, has an
- empty implementation of \l{QVariantAnimation::}{updateCurrentValue()}, and
- does not change any value unless we change it ourselves on the
+ As the QPropertyAnimation class can interpolate on Qt properties, it is
+ used often. In fact, its superclass---QVariantAnimation---provides an
+ abstract implementation of \l{QVariantAnimation::}{updateCurrentValue()},
+ which does not change any value unless you change it on the
\l{QVariantAnimation::valueChanged()}{valueChanged signal}.
- A major reason we chose to animate Qt properties is that it
- presents us with freedom to animate already existing classes in
- the Qt API. Notably, the QWidget class (which we can also embed in
- a QGraphicsView) has properties for its bounds, colors, etc.
- Let's look at a small example:
-
- \code
- QPushButton button("Animated Button");
- button.show();
+ The framework lets you animate the Qt properties of the existing
+ classes in Qt. For example, the QWidget class---can be embedded in
+ a QGraphicsView---has properties for its bounds, colors, and so on.
+ The following example demonstrates how you can animate a QPushButton
+ widget:
- QPropertyAnimation animation(&button, "geometry");
- animation.setDuration(10000);
- animation.setStartValue(QRect(0, 0, 100, 30));
- animation.setEndValue(QRect(250, 250, 100, 30));
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp 0
- animation.start();
- \endcode
+ The example animates the \c pos Qt property of a QPushButton, to move
+ it from the top--left corner of the screen to the end position (250, 250),
+ in 10 seconds (10000 milliseconds).
- This code will move \c button from the top left corner of the
- screen to the position (250, 250) in 10 seconds (10000 milliseconds).
-
- The example above will do a linear interpolation between the
- start and end value. It is also possible to set values
- situated between the start and end value. The interpolation
- will then go by these points.
+ It uses the linear interpolation method to control the speed of
+ animation between the start and end values. Try adding another value
+ in--between the start and end value to see how they are interpolated.
+ This time use the QPropertyAnimation::setKeyValueAt function to add
+ these values:
\code
- QPushButton button("Animated Button");
- button.show();
-
- QPropertyAnimation animation(&button, "geometry");
- animation.setDuration(10000);
-
- animation.setKeyValueAt(0, QRect(0, 0, 100, 30));
- animation.setKeyValueAt(0.8, QRect(250, 250, 100, 30));
- animation.setKeyValueAt(1, QRect(0, 0, 100, 30));
-
- animation.start();
+ ...
+ anim->setDuration(10000);
+ anim->setKeyValueAt(0, QPoint(0, 0));
+ anim->setKeyValueAt(0.8, QPoint(250, 250));
+ anim->setKeyValueAt(1, QPoint(0, 0));
+ ...
\endcode
- In this example, the animation will take the button to (250, 250)
- in 8 seconds, and then move it back to its original position in
- the remaining 2 seconds. The movement will be linearly
- interpolated between these points.
+ In this example, the animation moves the button to
+ (250, 250) in 8 seconds, and moves it back to its original position in
+ the remaining 2 seconds. The button's movement is linear-interpolated
+ between these points.
+
+ You can also animate a QObject's value that is not declared as a Qt
+ property, if the value has a setter method. In such cases, derive
+ a new class from the class that contains the value, and add a Qt property
+ for that value with the setter.
- You also have the possibility to animate values of a QObject
- that is not declared as a Qt property. The only requirement is
- that this value has a setter. You can then subclass the class
- containing the value and declare a property that uses this setter.
- Note that each Qt property requires a getter, so you will need to
- provide a getter yourself if this is not defined.
+ \note Each Qt property requires a getter also, so you should provide a
+ getter if that is not defined.
\code
class MyGraphicsRectItem : public QObject, public QGraphicsRectItem
{
Q_OBJECT
- Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
};
\endcode
- In the above code example, we subclass QGraphicsRectItem and
- define a geometry property. We can now animate the widgets
- geometry even if QGraphicsRectItem does not provide the geometry
- property.
+ In this example, the \c MyGraphicsRectItem derives from
+ QGraphicsRectItem and QObject, and defines the \c pos property. You can
+ animate the item's \c pos even if QGraphicsRectItem does not provide
+ the \c pos property.
- For a general introduction to the Qt property system, see its
- \l{Qt's Property System}{overview}.
+ For a general introduction to the Qt property system, refer to
+ \l{Qt's Property System}.
\section1 Animations and the Graphics View Framework
- When you want to animate \l{QGraphicsItem}s, you also use
- QPropertyAnimation. However, QGraphicsItem does not inherit QObject.
- A good solution is to subclass the graphics item you wish to animate.
- This class will then also inherit QObject.
- This way, QPropertyAnimation can be used for \l{QGraphicsItem}s.
- The example below shows how this is done. Another possibility is
- to inherit QGraphicsWidget, which already is a QObject.
+ QPropertyAnimation can also be used to animate a QGraphicsItem, which does
+ not inherit QObject. In such cases, you derive a class from the graphics
+ item that you want to animate. This derived class should also inherit form
+ QObject to enable using QPropertyAnimation on a QGraphicsItem. The
+ following example shows how this is done:
\code
class Pixmap : public QObject, public QGraphicsPixmapItem
@@ -176,121 +157,78 @@
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
...
+ }
\endcode
- As described in the previous section, we need to define
- properties that we wish to animate.
+ \note You can also derive from QGraphicsWidget, which already is a
+ QObject.
- Note that QObject must be the first class inherited as the
- meta-object system demands this.
+ As described in the previous section, you need to define
+ properties that you want to animate. The derived class must inherit
+ from QObject first as the meta-object system requires it.
- \section1 Easing Curves
+ \section1 Easing curves
- As mentioned, QPropertyAnimation performs an interpolation between
- the start and end property value. In addition to adding more key
- values to the animation, you can also use an easing curve. Easing
- curves describe a function that controls how the speed of the
- interpolation between 0 and 1 should be, and are useful if you
- want to control the speed of an animation without changing the
- path of the interpolation.
+ A QPropertyAnimation performs linear interpolation
+ between the start and end property values. In addition to adding more key
+ values to the animation, you can also choose an easing curve to control the
+ speed of interpolation between 0 and 1, without changing the
+ path.
- \code
- QPushButton button("Animated Button");
- button.show();
- QPropertyAnimation animation(&button, "geometry");
- animation.setDuration(3000);
- animation.setStartValue(QRect(0, 0, 100, 30));
- animation.setEndValue(QRect(250, 250, 100, 30));
-
- animation.setEasingCurve(QEasingCurve::OutBounce);
-
- animation.start();
- \endcode
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp easing-curve
- Here the animation will follow a curve that makes it bounce like a
- ball as if it was dropped from the start to the end position.
- QEasingCurve has a large collection of curves for you to choose
- from. These are defined by the QEasingCurve::Type enum. If you are
- in need of another curve, you can also implement one yourself, and
+ In this example, the animation follows a curve that makes the
+ \c button bounce like a ball. QEasingCurve offers a large collection of curves
+ to choose from the QEasingCurve::Type enum. If you want
+ to use another curve that is not available, implement one yourself and
register it with QEasingCurve.
- \omit Drop this for the first Lab release
- (Example of custom easing curve (without the actual impl of
- the function I expect)
- \endomit
+ \section1 Grouping animations
- \section1 Putting Animations Together
-
- An application will often contain more than one animation. For
- instance, you might want to move more than one graphics item
+ An application often contains more than one animation. For
+ example, it wants to move more than one graphics item
simultaneously or move them in sequence after each other.
- The subclasses of QAnimationGroup (QSequentialAnimationGroup and
- QParallelAnimationGroup) are containers for other animations so
+ The subclasses of QAnimationGroup---QSequentialAnimationGroup and
+ QParallelAnimationGroup---are containers for other animations so
that these animations can be animated either in sequence or
- parallel. The QAnimationGroup is an example of an animation that
- does not animate properties, but it gets notified of time changes
- periodically. This enables it to forward those time changes to its
- contained animations, and thereby controlling when its animations
- are played.
-
- Let's look at code examples that use both
- QSequentialAnimationGroup and QParallelAnimationGroup, starting
- off with the latter.
-
- \code
- QPushButton *bonnie = new QPushButton("Bonnie");
- bonnie->show();
+ parallel. The QAnimationGroup does not animate properties, but it
+ gets notified of time changes periodically. This enables it to
+ forward those time changes to the animation groups, which control when
+ their animations are played.
- QPushButton *clyde = new QPushButton("Clyde");
- clyde->show();
+ The two following examples demonstrate the use of both
+ QSequentialAnimationGroup and QParallelAnimationGroup:
- QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "geometry");
- // Set up anim1
-
- QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "geometry");
- // Set up anim2
-
- QParallelAnimationGroup *group = new QParallelAnimationGroup;
- group->addAnimation(anim1);
- group->addAnimation(anim2);
-
- group->start();
- \endcode
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp animation-group1
A parallel group plays more than one animation at the same time.
- Calling its \l{QAbstractAnimation::}{start()} function will start
- all animations it governs.
-
- \code
- QPushButton button("Animated Button");
- button.show();
+ Its \l{QAbstractAnimation::}{start()} function starts all
+ animations that are part of the group.
- QPropertyAnimation anim1(&button, "geometry");
- anim1.setDuration(3000);
- anim1.setStartValue(QRect(0, 0, 100, 30));
- anim1.setEndValue(QRect(500, 500, 100, 30));
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp animation-group2
- QPropertyAnimation anim2(&button, "geometry");
- anim2.setDuration(3000);
- anim2.setStartValue(QRect(500, 500, 100, 30));
- anim2.setEndValue(QRect(1000, 500, 100, 30));
+ As the name suggests, a QSequentialAnimationGroup plays
+ its animations in sequence. It starts the next animation in
+ the list after the previous finishes.
- QSequentialAnimationGroup group;
+ A group is an animation itself, so you can add
+ it to another group. This way, building an animation tree, which define
+ when the animations are played in relation to each other.
- group.addAnimation(&anim1);
- group.addAnimation(&anim2);
+ \section1 Object ownership
- group.start();
- \endcode
+ A QPropertyAnimation should always have a parent that controls
+ its lifespan. A typical application may include several animations that
+ are grouped, where the animation group takes ownership of those animations.
+ An independent QProperyAnimation must be explicitly assigned a parent to
+ control its lifespan. In the following example, you can see that an
+ independent QPropertyAnimation has the QApplication instance as its
+ parent:
- As you no doubt have guessed, QSequentialAnimationGroup plays
- its animations in sequence. It starts the next animation in
- the list after the previous is finished.
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp 0
- Since an animation group is an animation itself, you can add
- it to another group. This way, you can build a tree structure
- of animations which specifies when the animations are played
- in relation to each other.
+ \note You can also control the animation's lifespan by choosing a
+ \l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting it.
*/
diff --git a/src/corelib/doc/src/cbor.qdoc b/src/corelib/doc/src/cbor.qdoc
new file mode 100644
index 0000000000..22252bbd88
--- /dev/null
+++ b/src/corelib/doc/src/cbor.qdoc
@@ -0,0 +1,78 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \group cbor
+ \title CBOR Support in Qt
+ \ingroup qt-basic-concepts
+ \brief An overview of CBOR support in Qt.
+
+ \ingroup frameworks-technologies
+
+ \keyword CBOR
+
+ Qt provides support for dealing with CBOR data. CBOR is a binary format to
+ store data that has a superset of the types available in JSON, but is more
+ compact.
+
+ The CBOR support in Qt provides an easy to use C++ API to parse,
+ modify and save CBOR data.
+
+ More details about the CBOR data format can be found in \l {RFC 7049}.
+
+ \tableofcontents
+
+ \section1 Overview
+
+ CBOR is a format to store structured data. It has three groups of built-in types:
+
+ \list
+ \li Basic types: integers, floating point, boolean, null, etc.
+ \li String-like types: strings and byte arrays
+ \li Containers: arrays and maps
+ \endlist
+
+ In addition, CBOR can add a "tag" to extend the meaning of the type. The
+ container types can contain basic types, string-like types and containers.
+
+ \sa {Cbordump Example}, {Convert Example}, {JSON Save Game Example}
+
+ \section1 The CBOR Classes
+
+ \section2 The QCborValue Class
+
+ The QCborValue class represents any CBOR type. It also has a simple API for
+ reading and writing to QCborStreamReader and QCborStreamWriter objects, as
+ well as manipulating such objects in memory, with the help of QCborArray
+ and QCborMap. The CborValue API is simplified from the full CBOR data type
+ and always represents all integers as \l qint64 and all floating-point as
+ \c double. This means QCborValue is unable to represent CBOR integer values
+ outside of the range of \l qint64 (-2^63 to 2^63-1). When creating a CBOR
+ stream, QCborValue::toCbor() can be configured to attempt to write the
+ shorter single- and half-precision floating-point representations.
+
+ \section2 The QCborArray Class
+
+ The QCborArray class is used to hold an array of QCborValue objects. A
+ QCborValue object can contain a QCborArray object. It has functions for
+ converting to and from QVariantList, QStringList, QJsonArray.
+
+ \section2 The QCborMap Class
+
+ The QCborMap class is used to hold an map of QCborValue objects. A
+ QCborValue object can contain a QCborMap object. It has functions for
+ converting to and from QVariantMap, QVariantMap, and QJsonObject, but it
+ can have keys of any type, not just QString.
+
+ \section2 The QCborStreamReader Class
+
+ The QCborStreamReader class is a low level API for reading CBOR data from a
+ QIODevice, a QByteArray, or a pointer to memory. It has an API similar to
+ the QXmlStreamReader class.
+
+ \section2 The QCborStreamWriter Class
+
+ The QCborStreamWriter class is a low level API for writing CBOR data to a
+ QIODevice or a QByteArray. It has an API similar to the QXmlStreamWriter
+ class.
+*/
diff --git a/src/corelib/doc/src/cmake/cmake-commands.qdoc b/src/corelib/doc/src/cmake/cmake-commands.qdoc
index 7e98c16e41..e185bab624 100644
--- a/src/corelib/doc/src/cmake/cmake-commands.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-commands.qdoc
@@ -4,6 +4,7 @@
/*!
\group cmake-commands-qtcore
\title CMake Commands in Qt6 Core
+\brief Lists CMake commands defined in Qt6::Core.
The following CMake commands are defined when Qt6::Core is loaded, for instance
with
diff --git a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
index 116e08fef4..64275c35f7 100644
--- a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
@@ -10,6 +10,7 @@
/*!
\group cmake-variables-qtcore
\title CMake Variables in Qt6 Core
+\brief Lists CMake variables defined in Qt6::Core.
The following CMake variables are defined when Qt6::Core is loaded, for instance
with
@@ -22,7 +23,7 @@ find_package(Qt6 REQUIRED COMPONENTS Core)
*/
*/*!
-\page cmake-variable-ANDROID_NDK_HOST_SYSTEM_NAME.html
+\page cmake-variable-android-ndk-host-system-name.html
\ingroup cmake-variables-qtcore
\title ANDROID_NDK_HOST_SYSTEM_NAME
@@ -41,7 +42,7 @@ part of the deployment settings for a target.
*/
/*!
-\page cmake-variable-ANDROID_SDK_ROOT.html
+\page cmake-variable-android-sdk-root.html
\ingroup cmake-variables-qtcore
\title ANDROID_SDK_ROOT
@@ -60,7 +61,7 @@ It is written out as part of the deployment settings for a target.
*/
/*!
-\page cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS.html
+\page cmake-variable-qt-android-application-arguments.html
\ingroup cmake-variables-qtcore
\title QT_ANDROID_APPLICATION_ARGUMENTS
@@ -79,7 +80,88 @@ out as part of the deployment settings for a target.
*/
/*!
-\page cmake-variable-QT_ANDROID_BUILD_ALL_ABIS.html
+\page cmake_variable-qt-android-multi-abi-forward-vars
+\ingroup cmake-variables-qtcore
+
+\title QT_ANDROID_MULTI_ABI_FORWARD_VARS
+\target cmake-variable-QT_ANDROID_MULTI_ABI_FORWARD_VARS
+
+\summary {Allows to share CMake variables in multi-ABI builds}
+
+\cmakevariablesince 6.4.2
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+The \c{QT_ANDROID_MULTI_ABI_FORWARD_VARS} variable allows specifying the list of
+CMake variables that need to be forwarded from the main ABI project to
+ABI-specific subprojects. Due to the specifics of the Multi-ABI project build
+process, there is no generic way to forward the CMake cache variables
+that are specified either in the command line or in another similar way.
+
+A typical use case for the variable is propagating CMake cache variables
+specified in the command line. For example, a project has two variables
+\c{PROJECT_WIDE_VARIABLE1} and \c{PROJECT_WIDE_VARIABLE2} that affect the
+project configuration:
+\badcode
+cmake_minimum_required(VERSION 3.18)
+
+project(MyProject LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core)
+
+qt_add_executable(MyApp main.cpp)
+
+if(PROJECT_WIDE_VARIABLE1)
+ target_sources(MyApp PRIVATE sourcefile1.cpp)
+endif()
+if(PROJECT_WIDE_VARIABLE2)
+ target_sources(MyApp PRIVATE sourcefile2.cpp)
+endif()
+\endcode
+
+The above contents of \c{CMakeLists.txt} enable you to control how
+\c{MyApp} is built by setting the corresponding CMake variables from the
+command line:
+\badcode
+qt-cmake -S<source directory> -B<build directory> \
+ -DPROJECT_WIDE_VARIABLE1=ON \
+ -DPROJECT_WIDE_VARIABLE2=ON \
+ -DQT_ANDROID_MULTI_ABI_FORWARD_VARS="PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2"
+\endcode
+
+When configuring the application for desktop, \c{PROJECT_WIDE_VARIABLE1} and
+\c{PROJECT_WIDE_VARIABLE2} are visible in CMake listings and scripts as global
+cache variables. This doesn't work for Android Multi-ABI builds because
+ABI-specific subprojects do not inherit the cache variables from the main-ABI
+project. This issue can be solved by passing the list of required variables to
+the \c{QT_ANDROID_MULTI_ABI_FORWARD_VARS} variable, so both
+\c{PROJECT_WIDE_VARIABLE1} and \c{PROJECT_WIDE_VARIABLE2} values will be
+propagated to the ABI-specific builds.
+
+The variable can be also defined in the project's CMakeLists.txt:
+\badcode
+...
+qt_add_executable(MyApp main.cpp)
+...
+if(ANDROID)
+ set(QT_ANDROID_MULTI_ABI_FORWARD_VARS "PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2")
+endif()
+...
+\endcode
+
+Setting the variable in this way allows you to have a predefined set of
+variables that will always be forwarded to abi-specific projects.
+
+\note The forwarding is done in the target finalizer, which is implicitly
+called when \l{qt6_add_executable}{qt_add_executable()} is used. The
+finalization occurs automatically when using CMake 3.19 or later.
+
+\sa {qt6_finalize_target}{qt_finalize_target()},
+ {qt6_add_executable}{qt_add_executable()}
+*/
+
+/*!
+\page cmake-variable-qt-android-build-all-abis.html
\ingroup cmake-variables-qtcore
\title QT_ANDROID_BUILD_ALL_ABIS
@@ -98,11 +180,11 @@ supplied by the Qt installer, with the corresponding naming of the directories.
The typical directory structure looks as below:
\badcode
/path/to/Qt/6.x.x
-    android_armv7
-    android_arm64_v8a
-    android_x86
-    android_x86_64
-    ...
+ android_armv7
+ android_arm64_v8a
+ android_x86
+ android_x86_64
+ ...
\endcode
The auto-detected paths can be customized using one of \c{QT_PATH_ANDROID_ABI_<ABI>} variables.
@@ -112,7 +194,7 @@ The variable is set to FALSE by default.
*/
/*!
-\page cmake-variable-QT_ANDROID_ABIS.html
+\page cmake-variable-qt-android-abis.html
\ingroup cmake-variables-qtcore
\title QT_ANDROID_ABIS
@@ -137,7 +219,7 @@ QT_ANDROID_ABIS logic.
*/
/*!
-\page cmake-variable-QT_PATH_ANDROID_ABI.html
+\page cmake-variable-qt-path-android-abi.html
\ingroup cmake-variables-qtcore
\title QT_PATH_ANDROID_ABI_<ABI>
@@ -156,7 +238,32 @@ Each variable can be used to specify the path to Qt for Android for the correspo
*/
/*!
-\page cmake-variable-QT_ANDROID_SIGN_APK.html
+\page cmake-variable-qt-android-sign-aab.html
+\ingroup cmake-variables-qtcore
+
+\title QT_ANDROID_SIGN_AAB
+\target cmake-variable-QT_ANDROID_SIGN_AAB
+
+\summary {Sign the .aab package with the specified keystore, alias and store password.}
+\cmakevariablesince 6.4
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+Sign the resulting package. The path of the keystore file, the alias of the key and passwords
+have to be specified by additional environment variables:
+\badcode
+ QT_ANDROID_KEYSTORE_PATH
+ QT_ANDROID_KEYSTORE_ALIAS
+ QT_ANDROID_KEYSTORE_STORE_PASS
+ QT_ANDROID_KEYSTORE_KEY_PASS
+\endcode
+Mentioned variables are used internally by \l{androiddeployqt}.
+
+\sa{androiddeployqt}
+*/
+
+/*!
+\page cmake-variable-qt-android-sign-apk.html
\ingroup cmake-variables-qtcore
\title QT_ANDROID_SIGN_APK
@@ -181,7 +288,29 @@ Mentioned variables are used internally by \l{androiddeployqt}.
*/
/*!
-\page cmake-variable-QT_HOST_PATH.html
+\page cmake-variable-qt-no-collect-build-tree-apk-deps.html
+\ingroup cmake-variables-qtcore
+
+\title QT_NO_COLLECT_BUILD_TREE_APK_DEPS
+\target cmake-variable-QT_NO_COLLECT_BUILD_TREE_APK_DEPS
+
+\summary {Prevents collecting of project-built shared library targets during Android deployment.}
+
+\cmakevariablesince 6.3
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+During project finalization, the build system collects the locations of
+all built shared library targets in the project.
+These locations are passed to \l androiddeployqt for deployment consideration when
+resolving dependencies between libraries.
+Set \c QT_NO_COLLECT_BUILD_TREE_APK_DEPS to \c TRUE to disable this behavior.
+
+\sa {qt6_finalize_project}{qt_finalize_project()}
+*/
+
+/*!
+\page cmake-variable-qt-host-path.html
\ingroup cmake-variables-qtcore
\title QT_HOST_PATH
@@ -190,7 +319,6 @@ Mentioned variables are used internally by \l{androiddeployqt}.
\summary {Location of the host Qt installation when cross-compiling.}
\cmakevariablesince 6.0
-\preliminarycmakevariable
When cross-compiling, this must be set to the install location of Qt for the host
platform. It is used to locate tools to be run on the host (\l{moc}, \l{rcc},
@@ -198,7 +326,7 @@ platform. It is used to locate tools to be run on the host (\l{moc}, \l{rcc},
*/
/*!
-\page cmake-variable-QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID.html
+\page cmake-variable-qt-no-set-xcode-development-team-id.html
\ingroup cmake-variables-qtcore
\title QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID
@@ -215,7 +343,7 @@ Set \c QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID to true if you want to prevent this.
*/
/*!
-\page cmake-variable-QT_NO_SET_XCODE_BUNDLE_IDENTIFIER.html
+\page cmake-variable-qt-no-set-xcode-bundle-identifier.html
\ingroup cmake-variables-qtcore
\title QT_NO_SET_XCODE_BUNDLE_IDENTIFIER
@@ -233,7 +361,7 @@ Set \c QT_NO_SET_XCODE_BUNDLE_IDENTIFIER to true if you want to prevent this.
*/
/*!
-\page cmake-variable-QT_ENABLE_VERBOSE_DEPLOYMENT.html
+\page cmake-variable-qt-enable-verbose-deployment.html
\ingroup cmake-variables-qtcore
\title QT_ENABLE_VERBOSE_DEPLOYMENT
@@ -253,7 +381,7 @@ must be set before the first \c{find_package(Qt6)} call to have that effect.
*/
/*!
-\page cmake-variable-QT_DEPLOY_SUPPORT.html
+\page cmake-variable-qt-deploy-support.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_SUPPORT
@@ -280,7 +408,7 @@ an application, along with its runtime dependencies:
*/
/*!
-\page cmake-variable-QT_NO_STANDARD_PROJECT_SETUP.html
+\page cmake-variable-qt-no-standard-project-setup.html
\ingroup cmake-variables-qtcore
\title QT_NO_STANDARD_PROJECT_SETUP
@@ -302,3 +430,22 @@ methods provided by CMake.
\sa {qt6_standard_project_setup}{qt_standard_project_setup()}
*/
+
+/*!
+\page cmake-variable-qt-ios-launch-screen.html
+\ingroup cmake-variables-qtcore
+
+\title QT_IOS_LAUNCH_SCREEN
+\target cmake-variable-QT_IOS_LAUNCH_SCREEN
+
+\summary {Path to iOS launch screen storyboard used by all targets}
+
+\cmakevariablesince 6.4
+\preliminarycmakevariable
+\cmakevariableiosonly
+
+Specifies the path to an iOS launch screen storyboard file that will be used
+by all targets within a project.
+
+\sa {Launch Screens and Launch Images}
+*/
diff --git a/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc b/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
index b10de9dc3b..0a0902e0de 100644
--- a/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
@@ -8,7 +8,7 @@
**/
/*!
-\page cmake-variable-QT_DEPLOY_PREFIX.html
+\page cmake-variable-qt-deploy-prefix.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_PREFIX
@@ -53,7 +53,7 @@ variables.
*/
/*!
-\page cmake-variable-QT_DEPLOY_BIN_DIR.html
+\page cmake-variable-qt-deploy-bin-dir.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_BIN_DIR
@@ -94,7 +94,7 @@ should not be used for that scenario.
*/
/*!
-\page cmake-variable-QT_DEPLOY_LIB_DIR.html
+\page cmake-variable-qt-deploy-lib-dir.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_LIB_DIR
@@ -136,7 +136,7 @@ should not be used for that scenario.
*/
/*!
-\page cmake-variable-QT_DEPLOY_PLUGINS_DIR.html
+\page cmake-variable-qt-deploy-plugins-dir.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_PLUGINS_DIR
@@ -172,7 +172,7 @@ bundle contents.
*/
/*!
-\page cmake-variable-QT_DEPLOY_QML_DIR.html
+\page cmake-variable-qt-deploy-qml-dir.html
\ingroup cmake-variables-qtcore
\title QT_DEPLOY_QML_DIR
diff --git a/src/corelib/doc/src/cmake/cmake-properties.qdoc b/src/corelib/doc/src/cmake/cmake-properties.qdoc
index bbb948aec2..fbb75c1830 100644
--- a/src/corelib/doc/src/cmake/cmake-properties.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-properties.qdoc
@@ -4,6 +4,7 @@
/*!
\group cmake-target-properties-qtcore
\title CMake Target Properties in Qt6 Core
+\brief Lists CMake target properties known to Qt6::Core.
\l{CMake Commands in Qt6 Core}{CMake Commands} know about the following CMake
target properties:
@@ -12,7 +13,7 @@ target properties:
*/
/*!
-\page cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES.html
+\page cmake-target-property-qt-android-deployment-dependencies.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -43,7 +44,7 @@ is listed before its dependencies, it will fail to load on some devices.
*/
/*!
-\page cmake-target-property-QT_ANDROID_EXTRA_LIBS.html
+\page cmake-target-property-qt-android-extra-libs.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -65,7 +66,7 @@ to enable OpenSSL in your application. For more information, see
*/
/*!
-\page cmake-target-property-QT_ANDROID_EXTRA_PLUGINS.html
+\page cmake-target-property-qt-android-extra-plugins.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -96,7 +97,7 @@ mangling is applied to the plugin library.
*/
/*!
-\page cmake-target-property-QT_ANDROID_MIN_SDK_VERSION.html
+\page cmake-target-property-qt-android-min-sdk-version.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -115,7 +116,7 @@ Specifies the minimum Android API level for the target.
*/
/*!
-\page cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR.html
+\page cmake-target-property-qt-android-package-source-dir.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -148,7 +149,7 @@ then place this directly into the directory specified by this variable.
*/
/*!
-\page cmake-target-property-QT_ANDROID_TARGET_SDK_VERSION.html
+\page cmake-target-property-qt-android-target-sdk-version.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -167,7 +168,27 @@ Specifies the target Android API level for the target.
*/
/*!
-\page cmake-target-property-QT_ANDROID_VERSION_CODE.html
+\page cmake-target-property-qt-android-sdk-build-tools-revision.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+
+\title QT_ANDROID_SDK_BUILD_TOOLS_REVISION
+\target cmake-target-property-QT_ANDROID_SDK_BUILD_TOOLS_REVISION
+
+\summary {Revision of Android build tools to use.}
+
+\cmakepropertysince 6.0
+\preliminarycmakeproperty
+\cmakepropertyandroidonly
+
+Specifies the Android SDK build tools revision to use. If this is not set then
+CMake will attempt to use the latest installed version.
+
+\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
+*/
+
+/*!
+\page cmake-target-property-qt-android-version-code.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -189,7 +210,7 @@ For more information, see \l{Android: App Versioning}{Android App Versioning}.
*/
/*!
-\page cmake-target-property-QT_ANDROID_VERSION_NAME.html
+\page cmake-target-property-qt-android-version-name.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -211,7 +232,7 @@ For more information, see \l{Android: App Versioning}{Android App Versioning}.
*/
/*!
-\page cmake-target-property-QT_ANDROID_ABIS.html
+\page cmake-target-property-qt-android-abis.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -234,7 +255,7 @@ The property only affects targets created with
*/
/*!
-\page cmake-target-property-QT_QML_ROOT_PATH.html
+\page cmake-target-property-qt-qml-root-path.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -255,7 +276,7 @@ will be used instead.
*/
/*!
-\page cmake-target-property-QT_QML_IMPORT_PATH.html
+\page cmake-target-property-qt-qml-import-path.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -277,7 +298,7 @@ For application-specific QML imports, use
*/
/*!
-\page cmake-target-property-QT_ANDROID_DEPLOYMENT_SETTINGS_FILE.html
+\page cmake-target-property-qt-android-deployment-settings-file.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -297,7 +318,7 @@ and overwritten by that command.
*/
/*!
-\page cmake-target-property-QT_ANDROID_SYSTEM_LIBS_PREFIX.html
+\page cmake-target-property-qt-android-system-libs-prefix.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -314,7 +335,7 @@ when those libraries are installed outside app's native (JNI) library directory.
*/
/*!
-\page cmake-target-property-QT_ANDROID_NO_DEPLOY_QT_LIBS.html
+\page cmake-target-property-qt-android-no-deploy-qt-libs.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -336,7 +357,7 @@ instead.
*/
/*!
-\page cmake-target-property-qt_no_entrypoint.html
+\page cmake-target-property-qt-no-entrypoint.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -355,7 +376,7 @@ On targets that must provide their own entry point, set the property \c qt_no_en
*/
/*!
-\page cmake-target-property-qt_resource_prefix.html
+\page cmake-target-property-qt-resource-prefix.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -375,6 +396,7 @@ resource prefix.
/*!
\group cmake-source-file-properties-qtcore
\title CMake Source File Properties in Qt6 Core
+\brief Lists CMake file properties used in Qt6::Core.
\l{CMake Commands in Qt6 Core}{CMake Commands} know about the following CMake
source file properties:
@@ -383,7 +405,7 @@ source file properties:
*/
/*!
-\page cmake-source-file-property-QT_RESOURCE_ALIAS.html
+\page cmake-source-file-property-qt-resource-alias.html
\ingroup cmake-source-file-properties-qtcore
\title QT_RESOURCE_ALIAS
@@ -401,7 +423,7 @@ the property value overrides the runtime path where the resource file is found.
*/
/*!
-\page cmake-target-property-QT_WASM_PTHREAD_POOL_SIZE.html
+\page cmake-target-property-qt-wasm-pthread-pool-size.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -425,7 +447,7 @@ For more information, see \l{https://emscripten.org/docs/porting/pthreads.html}{
*/
/*!
-\page cmake-target-property-QT_WASM_INITIAL_MEMORY.html
+\page cmake-target-property-qt-wasm-initial-memory.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -445,3 +467,22 @@ QT_WASM_INITIAL_MEMORY must be a multiple of 65536 bytes.
For more information, see \l{https://github.com/emscripten-core/emscripten/blob/main/src/settings.js}{Emscripten compiler settings}.
*/
+
+/*!
+\page cmake-target-property-qt-ios-launch-screen.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+
+\title QT_IOS_LAUNCH_SCREEN
+\target cmake-target-property-QT_IOS_LAUNCH_SCREEN
+
+\summary {Path to iOS launch screen storyboard}
+
+\cmakepropertysince 6.4
+\preliminarycmakeproperty
+\cmakepropertyiosonly
+
+Specifies the path to an iOS launch screen storyboard file.
+
+\sa {Launch Screens and Launch Images}
+*/
diff --git a/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
index 5ae7b9728b..72a00e6eef 100644
--- a/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_bigresources.html
+\page qt-add-bigresources.html
\ingroup cmake-commands-qtcore
\title qt_add_big_resources
diff --git a/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
index a247b6d7c0..71ee8b894e 100644
--- a/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_binary_resources.html
+\page qt-add-binary-resources.html
\ingroup cmake-commands-qtcore
\title qt_add_binary_resources
diff --git a/src/corelib/doc/src/cmake/qt_add_executable.qdoc b/src/corelib/doc/src/cmake/qt_add_executable.qdoc
index a09ecc8dfd..c68366cdf8 100644
--- a/src/corelib/doc/src/cmake/qt_add_executable.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_executable.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_executable.html
+\page qt-add-executable.html
\ingroup cmake-commands-qtcore
\title qt_add_executable
@@ -60,25 +60,34 @@ for you as a convenience.
After a target is created, further processing or \e{finalization} steps are
commonly needed. The steps to perform depend on the platform and on various
-properties of the target. The finalization processing is implemented by the
-\l{qt6_finalize_target}{qt_finalize_target()} command. You might need to also
-call the \l{qt6_finalize_project}{qt_finalize_project()} command at the end
-of top-level CMakeLists.txt to correctly resolve the dependencies between
-project targets.
-
-Finalization can occur either as part of this call or be deferred to sometime
-after this command returns (but it should still be in the same directory scope).
-When using CMake 3.19 or later, finalization is automatically deferred to the
+properties of the target.
+
+The finalization processing is implemented by two commands:
+\l{qt6_finalize_target}{qt_finalize_target()} and
+\l{qt6_finalize_project}{qt_finalize_project()}.
+
+Target finalization can occur either as part of calling \c{qt_add_executable}
+or be deferred to sometime after this command returns (but it should still be in
+the same directory scope).
+
+When using CMake 3.19 or later, target finalization is automatically deferred to the
end of the current directory scope. This gives the caller an opportunity to
modify properties of the created target before it is finalized. When using
CMake versions earlier than 3.19, automatic deferral isn't supported. In that
-case, finalization is performed immediately before this command returns.
+case, target finalization is performed immediately before this command returns.
Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
indicate that you will explicitly call \l{qt6_finalize_target}{qt_finalize_target()}
yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
not be needed unless the project has to support CMake 3.18 or earlier.
+Project finalization occurs automatically when using CMake 3.19 or later.
+When using an older CMake version, you should call
+\l{qt6_finalize_project}{qt_finalize_project()} manually, at the end
+of the root \c CMakeLists.txt file.
+This is especially important when targeting Android, to collect dependencies
+between project targets for deployment purposes.
+
\sa {qt6_finalize_target}{qt_finalize_target()},
{qt6_set_finalizer_mode}{qt_set_finalizer_mode()},
{qt6_add_library}{qt_add_library()},
diff --git a/src/corelib/doc/src/cmake/qt_add_library.qdoc b/src/corelib/doc/src/cmake/qt_add_library.qdoc
index 52b85d0476..ae1da18eee 100644
--- a/src/corelib/doc/src/cmake/qt_add_library.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_library.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_library.html
+\page qt-add-library.html
\ingroup cmake-commands-qtcore
\title qt_add_library
diff --git a/src/corelib/doc/src/cmake/qt_add_plugin.qdoc b/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
index 89a68dbee2..b69d30d62a 100644
--- a/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_plugin.html
+\page qt-add-plugin.html
\ingroup cmake-commands-qtcore
\title qt_add_plugin
diff --git a/src/corelib/doc/src/cmake/qt_add_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_resources.qdoc
index 7de9b94854..2bca258980 100644
--- a/src/corelib/doc/src/cmake/qt_add_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_resources.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_add_resources.html
+\page qt-add-resources.html
\ingroup cmake-commands-qtcore
\title qt_add_resources
diff --git a/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc b/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
index 8219380bd5..617baa0109 100644
--- a/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_allow_non_utf8_sources.html
+\page qt-allow-non-utf8-sources.html
\ingroup cmake-commands-qtcore
\title qt_allow_non_utf8_sources
diff --git a/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc b/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
index 7818596c76..747849eabb 100644
--- a/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_android_add_apk_target.html
+\page qt-android-add-apk-target.html
\ingroup cmake-commands-qtcore
\title qt_android_add_apk_target
diff --git a/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc b/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
index 5451a6727c..4d4585693d 100644
--- a/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_android_apply_arch_suffix.html
+\page qt-android-apply-arch-suffix.html
\ingroup cmake-commands-qtcore
\title qt_android_apply_arch_suffix
diff --git a/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc b/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
index 4df3a32101..a717c80e7c 100644
--- a/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_android_generate_deployment_settings.html
+\page qt-android-generate-deployment-settings.html
\ingroup cmake-commands-qtcore
\title qt_android_generate_deployment_settings
diff --git a/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc b/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
index 4f2b638835..ca17206925 100644
--- a/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
+++ b/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_deploy_qt_conf.html
+\page qt-deploy-qt-conf.html
\ingroup cmake-commands-qtcore
\title qt_deploy_qt_conf
diff --git a/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc b/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
index 6f950b4020..083d8da095 100644
--- a/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
+++ b/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_deploy_runtime_dependencies.html
+\page qt-deploy-runtime-dependencies.html
\ingroup cmake-commands-qtcore
\title qt_deploy_runtime_dependencies
diff --git a/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc b/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
index b056afea85..f4ad3c6426 100644
--- a/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
+++ b/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_disable_unicode_defines.html
+\page qt-disable-unicode-defines.html
\ingroup cmake-commands-qtcore
\title qt_disable_unicode_defines
diff --git a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
index a430989036..837baa3f0c 100644
--- a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
+++ b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_extract_metatypes.html
+\page qt-extract-metatypes.html
\ingroup cmake-commands-qtcore
\title qt_extract_metatypes
diff --git a/src/corelib/doc/src/cmake/qt_finalize_project.qdoc b/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
index dc63e66cd6..af7707f116 100644
--- a/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
+++ b/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
@@ -2,13 +2,13 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_finalize_project.html
+\page qt-finalize-project.html
\ingroup cmake-commands-qtcore
\title qt_finalize_project
\target qt6_finalize_project
-\summary {Handles various common platform-specific tasks associated with Qt project.}
+\summary {Handles various common platform-specific tasks associated with a Qt project.}
\preliminarycmakecommand
\include cmake-find-package-core.qdocinc
@@ -26,13 +26,17 @@ qt_finalize_project()
\section1 Description
Some targets that are created using Qt commands require additional actions
-at the end of CMake configuring phase. Depending on the platform the function
-typically walks through the build tree, resolves dependencies between targets
-created by the user, and applies extra deployment steps.
-
-With CMake versions 3.19 and higher, you don't need to call this command since
+at the end of CMake configuring phase.
+Depending on the platform, the function typically:
+\list
+ \li Walks the build tree.
+ \li Resolves dependencies.
+ \li Applies any extra deployment steps.
+\endlist
+
+With CMake version 3.19 or later, you don't need to call this command since
it consists of sub-commands that are ordinarily invoked at the end of
-\c CMAKE_SOURCE_DIR scope.
+\c CMAKE_SOURCE_DIR directory scope processing.
\include cmake-android-qt-finalize-project-warning.cmake
@@ -44,4 +48,5 @@ function:
\snippet cmake-macros/examples.cmake qt_finalize_project_manual
+\sa {cmake-variable-QT_NO_COLLECT_BUILD_TREE_APK_DEPS}{QT_NO_COLLECT_BUILD_TREE_APK_DEPS}
*/
diff --git a/src/corelib/doc/src/cmake/qt_finalize_target.qdoc b/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
index 558e89991f..277c32ea57 100644
--- a/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
+++ b/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_finalize_target.html
+\page qt-finalize-target.html
\ingroup cmake-commands-qtcore
\title qt_finalize_target
diff --git a/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc b/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
index b3a3328098..164bc3350b 100644
--- a/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
+++ b/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_generate_deploy_app_script.html
+\page qt-generate-deploy-app-script.html
\ingroup cmake-commands-qtcore
\title qt_generate_deploy_app_script
diff --git a/src/corelib/doc/src/cmake/qt_generate_moc.qdoc b/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
index 4f60ae1ae2..55b6df9e7d 100644
--- a/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
+++ b/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_generate_moc.html
+\page qt-generate-moc.html
\ingroup cmake-commands-qtcore
\title qt_generate_moc
diff --git a/src/corelib/doc/src/cmake/qt_import_plugins.qdoc b/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
index cea6fc61f5..b9606654b0 100644
--- a/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
+++ b/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_import_plugins.html
+\page qt-import-plugins.html
\ingroup cmake-commands-qtcore
\title qt_import_plugins
diff --git a/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc b/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
index 476c63ccc0..f44a217544 100644
--- a/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
+++ b/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_set_finalizer_mode.html
+\page qt-set-finalizer-mode.html
\ingroup cmake-commands-qtcore
\title qt_set_finalizer_mode
diff --git a/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc b/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
index b94d688e49..837aee304a 100644
--- a/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
+++ b/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_standard_project_setup.html
+\page qt-standard-project-setup.html
\ingroup cmake-commands-qtcore
\title qt_standard_project_setup
diff --git a/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc b/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
index 8390b81cd3..c2a916c71c 100644
--- a/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
+++ b/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qt_wrap_cpp.html
+\page qt-wrap-cpp.html
\ingroup cmake-commands-qtcore
\title qt_wrap_cpp
diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc
index bed184de15..4a7d5dc1bb 100644
--- a/src/corelib/doc/src/containers.qdoc
+++ b/src/corelib/doc/src/containers.qdoc
@@ -39,7 +39,8 @@
\note Since Qt 5.14, range constructors are available for most of the
container classes. QMultiMap is a notable exception. Their use is
- encouraged in place of the various from/to methods. For example:
+ encouraged to replace of the various deprecated from/to methods of Qt 5.
+ For example:
\snippet code/doc_src_containers.cpp 25
@@ -191,7 +192,30 @@
the C++ language doesn't specify any initialization; in those
cases, Qt's containers automatically initialize the value to 0.
- \section1 The Iterator Classes
+ \section1 Iterating over Containers
+
+ \section2 Range-based for
+
+ Range-based \c for should preferably be used for containers:
+
+ \snippet code/doc_src_containers.cpp range_for
+
+ Note that when using a Qt container in a non-const context,
+ \l{implicit sharing} may perform an undesired detach of the container.
+ To prevent this, use \c std::as_const():
+
+ \snippet code/doc_src_containers.cpp range_for_as_const
+
+ For associative containers, this will loop over the values.
+
+ \section2 Index-based
+
+ For sequential containers that store their items contiguously in memory
+ (for example, QList), index-based iteration can be used:
+
+ \snippet code/doc_src_containers.cpp index
+
+ \section2 The Iterator Classes
Iterators provide a uniform means to access items in a container.
Qt's container classes provide two types of iterators: STL-style
@@ -200,7 +224,7 @@
from \l{Implicit Sharing}{implicitly shared copies} due to a call
to a non-const member function.
- \section2 STL-Style Iterators
+ \section3 STL-Style Iterators
STL-style iterators have been available since the release of Qt
2.0. They are compatible with Qt's and STL's \l{generic
@@ -262,12 +286,10 @@
In the code snippets so far, we used the unary \c * operator to
retrieve the item (of type QString) stored at a certain iterator
- position, and we then called QString::toLower() on it. Most C++
- compilers also allow us to write \c{i->toLower()}, but some
- don't.
+ position, and we then called QString::toLower() on it.
- For read-only access, you can use const_iterator, \l{QList::constBegin}{constBegin()},
- and \l{QList::constEnd()}{constEnd()}. For example:
+ For read-only access, you can use const_iterator, \l{QList::cbegin}{cbegin()},
+ and \l{QList::cend()}{cend()}. For example:
\snippet code/doc_src_containers.cpp 12
@@ -315,7 +337,7 @@
This problem doesn't occur with functions that return a const or
non-const reference to a container.
- \section3 Implicit sharing iterator problem
+ \section4 Implicit sharing iterator problem
\l{Implicit sharing} has another consequence on STL-style
iterators: you should avoid copying a container while
@@ -328,33 +350,11 @@
The above example only shows a problem with QList, but
the problem exists for all the implicitly shared Qt containers.
- \section2 Java-Style Iterators
+ \section3 Java-Style Iterators
\l{java-style-iterators}{Java-Style iterators} were introduced in Qt 4. Their API is modelled
on Java's iterator classes.
New code should should prefer \l{STL-Style Iterators}.
- \section1 Container keywords
-
- \target foreach
- \section2 The foreach Keyword
- \l{foreach-keyword}{The foreach keyword} is discouraged, new code should
- prefer C++11 range-based loops.
-
- \target forever
- \section2 The forever keyword.
- In addition to \c foreach, Qt also provides a \c forever
- pseudo-keyword for infinite loops:
-
- \snippet code/doc_src_containers.cpp 21
-
- If you're worried about namespace pollution, you can disable
- these macros by adding the following line to your \c .pro file:
-
- \snippet code/doc_src_containers.cpp 22
-
- \note The alternative macros Q_FOREACH and Q_FOREVER remain defined
- regardless.
-
\section1 Qt containers compared with std containers
\table
@@ -383,7 +383,7 @@
\li Similar to std::queue<T>, inherits from \l{QList}.
\row \li \l{QSet}<T>
- \li Similar to std::set<T>. Internally, \l{QSet} is implemented with a
+ \li Similar to std::unordered_set<T>. Internally, \l{QSet} is implemented with a
\l{QHash}.
\row \li \l{QMap}<Key, T>
@@ -393,16 +393,16 @@
\li Similar to std::multimap<T>.
\row \li \l{QHash}<Key, T>
- \li Most similar to std::map<T>.
+ \li Most similar to std::unordered_map<T>.
\row \li \l{QMultiHash}<Key, T>
- \li Most similar to std::multimap<T>.
+ \li Most similar to std::unordered_multimap<T>.
\endtable
\section1 Qt containers and std algorithms
- You can used Qt containers with functions from \c{#include <algorithm>}.
+ You can use Qt containers with functions from \c{#include <algorithm>}.
\snippet code/doc_src_containers.cpp 26
@@ -410,7 +410,7 @@
Qt includes other template classes that resemble containers in
some respects. These classes don't provide iterators and cannot
- be used with the \c foreach keyword.
+ be used with the \l foreach keyword.
\list
\li QCache<Key, T> provides a cache to store objects of a certain
diff --git a/src/corelib/doc/src/datastreamformat.qdoc b/src/corelib/doc/src/datastreamformat.qdoc
index c3e57a9adf..60ea1aa495 100644
--- a/src/corelib/doc/src/datastreamformat.qdoc
+++ b/src/corelib/doc/src/datastreamformat.qdoc
@@ -67,5 +67,6 @@
\li QVector4D
\endlist
- \sa {JSON Support in Qt}
+ \sa {JSON Support in Qt}, {CBOR Support in Qt}
+
*/
diff --git a/src/corelib/doc/src/external-resources.qdoc b/src/corelib/doc/src/external-resources.qdoc
index 7e8977dbd9..3210d92cc7 100644
--- a/src/corelib/doc/src/external-resources.qdoc
+++ b/src/corelib/doc/src/external-resources.qdoc
@@ -83,6 +83,36 @@
*/
/*!
+ \externalpage https://developer.android.com/training/data-storage/shared/documents-files
+ \title Android: Access documents and other files from shared storage
+*/
+
+/*!
+ \externalpage https://developer.android.com/reference/androidx/documentfile/provider/DocumentFile#getParentFile()
+ \title Android: DocumentFile.getParentFile()
+*/
+
+/*!
+ \externalpage https://developer.android.com/guide/topics/providers/content-provider-basics#ContentURIs
+ \title Android: Content URIs
+*/
+
+/*!
+ \externalpage https://developer.android.com/training/data-storage#scoped-storage
+ \title Android: Scoped storage
+*/
+
+/*!
+ \externalpage https://developer.android.com/training/data-storage/use-cases
+ \title Android: storage best practices
+*/
+
+/*!
+ \externalpage https://developer.android.com/reference/android/provider/MediaStore
+ \title Android: MediaStore
+*/
+
+/*!
\externalpage https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
\title GNUInstallDirs
*/
diff --git a/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc b/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc
new file mode 100644
index 0000000000..f08086407e
--- /dev/null
+++ b/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc
@@ -0,0 +1,13 @@
+On Android, some limitations apply when dealing with
+\l {Android: Content URIs}{content URIs}:
+\list
+ \li Access permissions might be needed by prompting the user through the
+ \l QFileDialog which implements
+ \l {Access documents and other files from shared storage}{Android's native file picker}.
+ \li Aim to follow the \l {Android: Scoped storage}{Scoped storage} guidelines,
+ such as using app specific directories instead of other public external directories.
+ For more information, also see
+ \l {Android: storage best practices}{storage best practices}.
+ \li Due to the design of Qt APIs (e.g. QFile), it's not possible to fully
+ integrate the latter APIs with Android's \l {Android: MediaStore}{MediaStore} APIs.
+\endlist
diff --git a/src/corelib/doc/src/io.qdoc b/src/corelib/doc/src/io.qdoc
index 80caf9a769..443d324f75 100644
--- a/src/corelib/doc/src/io.qdoc
+++ b/src/corelib/doc/src/io.qdoc
@@ -10,7 +10,7 @@
network handling.
These \l{Qt Core} classes are used to handle input and output to and from
- external devices, processes, files etc. as well as manipulating files and
+ external devices, processes, files etc., as well as manipulating files and
directories.
*/
diff --git a/src/corelib/doc/src/qtcore-index.qdoc b/src/corelib/doc/src/qtcore-index.qdoc
index 377e199784..99cc114d64 100644
--- a/src/corelib/doc/src/qtcore-index.qdoc
+++ b/src/corelib/doc/src/qtcore-index.qdoc
@@ -75,6 +75,7 @@
\list
\li \l{The Animation Framework}
\li \l{JSON Support in Qt}
+ \li \l{CBOR Support in Qt}
\li \l{How to Create Qt Plugins}
\li \l{The Event System}
\endlist
diff --git a/src/corelib/doc/src/qtcore.qdoc b/src/corelib/doc/src/qtcore.qdoc
index 2ef705dd75..a46add1342 100644
--- a/src/corelib/doc/src/qtcore.qdoc
+++ b/src/corelib/doc/src/qtcore.qdoc
@@ -18,9 +18,17 @@
/*!
\module QtCorePrivate
\title Qt Core Private C++ Classes
- \qtcmakepackage CorePrivate
\qtvariable core-private
-
- \brief Provides private core functionality.
\preliminary
+ \brief Provides private core functionality.
+
+//! [qtcoreprivate-usage]
+ When building with CMake, use the following commands to use
+ private Qt Core APIs:
+
+ \badcode
+ find_package(Qt6 REQUIRED COMPONENTS Core)
+ target_link_libraries(mytarget PRIVATE Qt6::CorePrivate)
+ \endcode
+//! [qtcoreprivate-usage]
*/
diff --git a/src/corelib/doc/src/qtserialization.qdoc b/src/corelib/doc/src/qtserialization.qdoc
new file mode 100644
index 0000000000..dfceed55f2
--- /dev/null
+++ b/src/corelib/doc/src/qtserialization.qdoc
@@ -0,0 +1,138 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtserialization.html
+ \title Qt Serialization
+ \brief Serializations provided by Qt API
+
+ The purpose of serialization is to save the state of an object to be able to
+ recreate it when needed. It allows you to perform actions like:
+
+ \list
+ \li Sending the object to a remote application by using a web service
+ \li Passing the object as a JSON or XML string
+ \li Saving and restoring user information or sharing it across applications
+ \endlist
+
+ The Qt API provides support for serialization for several use cases:
+
+ \list
+ \li \l JSON support in Qt provides an easy to use C++ API to parse, modify
+ and save JSON data. \l {CBOR} {CBOR Support in Qt} is a compact form
+ of binary data encoding that is a superset of JSON.
+ \li \l QDataStream provides serialization of binary data to a QIODevice
+ \li \l {Qt XML C++ Classes} provide C++ implementations of the \l XML Streaming
+ and DOM standards for XML
+ \li \l CBOR is Qt's implementation for the CBOR serialization format.
+ \li \l QSettings provides a way of serializing and storing platform independent
+ application settings.
+ \endlist
+
+ \section1 Advantages of JSON and CBOR
+
+ When you use \l JSON information is stored in a QJsonObject and a QJsonDocument
+ takes care to stream values into a QByteArray.
+
+ For example
+ \code
+ QJsonObject jobject;
+ jobject["SensorID"] = m_id;
+ jobject["AmbientTemperature"] = m_ambientTemperature;
+ jobject["ObjectTemperature"] = m_objectTemperature;
+ jobject["AccelerometerX"] = m_accelerometerX;
+ jobject["AccelerometerY"] = m_accelerometerY;
+ jobject["AccelerometerZ"] = m_accelerometerZ;
+ jobject["Altitude"] = m_altitude;
+ jobject["Light"] = m_light;
+ jobject["Humidity"] = m_humidity;
+ QJsonDocument doc( jobject );
+
+ return doc.toJson();
+ \endcode
+
+ JSON has several advantages:
+
+ \list
+ \li Textual JSON is declarative, which makes it readable to humans
+ \li The information is structured
+ \li Exchanging generic information is easy
+ \li JSON allows extending messages with additional values
+ \li Many solutions exist to receive and parse JSON in cloud-based solutions
+ \endlist
+
+ \l CBOR is the Concise Binary Object Representation, a very compact form of
+ binary data encoding that is a superset of JSON. It was created by the IETF
+ Constrained RESTful Environments (CoRE) WG, which has been used in many new
+ RFCs. CBOR shares many of the advantages of JSON, but sacrifices human
+ readability for compactness.
+
+ \section1 Advantages of QDataStream Classes
+
+ \l QDataStream is a viable option when the whole flow of data is determined
+ and not about to change. In addition, both the reader and the writer of the
+ data must be written in Qt.
+
+ Adding support for this to a class requires two additional operators.
+ For example, for a class named SensorInformation:
+
+ \code
+ QDataStream &operator<<(QDataStream &, const SensorInformation &);
+ QDataStream &operator>>(QDataStream &, SensorInformation &);
+ \endcode
+
+ The implementation for the serialization is shown below:
+
+ \code
+ QDataStream &operator<<(QDataStream &out, const SensorInformation &item)
+ {
+ QDataStream::FloatingPointPrecision prev = out.floatingPointPrecision();
+ out.setFloatingPointPrecision(QDataStream::DoublePrecision);
+ out << item.m_id
+ << item.m_ambientTemperature
+ << item.m_objectTemperature
+ << item.m_accelerometerX
+ << item.m_accelerometerY
+ << item.m_accelerometerZ
+ << item.m_altitude
+ << item.m_light
+ << item.m_humidity;
+ out.setFloatingPointPrecision(prev);
+ return out;
+ }
+ \endcode
+
+ Deserialization works similarly, but using the \c {>>} operator.
+ For example, \c {out >> item.m_id}, and so on.
+
+ Usually, using QDataStream is faster than using textual JSON.
+
+ \section1 Advantages of Qt XML C++ Classes
+
+ Qt provides the QDomDocument class that represents the XML document and
+ two classes for reading and writing the XML through a simple streaming API:
+ QXmlStreamReader and QXmlStreamWriter.
+
+ QDomDocument class represents the entire XML document. It is the root of the
+ document tree and provides primary access to the document's data.
+
+ A stream reader reports an XML document as a stream of tokens. This differs
+ from SAX as SAX applications provide handlers to receive XML events from the
+ parser, whereas the QXmlStreamReader drives the loop, pulling tokens from the
+ reader when they are needed. This pulling approach makes it possible to build
+ recursive descent parsers, allowing XML parsing code to be split into
+ different methods or classes.
+
+ QXmlStreamReader a parser for well-formed XML 1.0, excluding external parsed
+ entities. Hence, data provided to the stream reader adheres to the
+ W3C's criteria for well-formed XML, or an error will be raised. Functions
+ such as \c atEnd(), \c error(), and \c hasError() can be used to test for
+ such errors and obtain a description of them.
+
+ The QXmlStreamWriter is a streaming API that takes care of prefixing namespaces,
+ when the namespaceUri is specified when writing elements or attributes.
+
+ \section1 Classes that provide serialization
+
+ \annotatedlist qtserialization
+*/
diff --git a/src/corelib/doc/src/resource-system.qdoc b/src/corelib/doc/src/resource-system.qdoc
index 45934a29d0..8cee601c67 100644
--- a/src/corelib/doc/src/resource-system.qdoc
+++ b/src/corelib/doc/src/resource-system.qdoc
@@ -110,6 +110,15 @@
\snippet resource-system/application.pro 1
+ This creates a resource of several \c{.png} files, that are addressable
+ like this: \c{":/images/copy.png"}.
+
+ If the directory layout of the files you want to embed into the resource
+ doesn't match the expectations of the application, you can specify
+ \c{resources.base}. \c base is a path prefix that denotes the root point of
+ the file's alias. In the example above, if \c{resources.base} is set to
+ \c{"images"}, then \c{copy.png} is addressable as \c{":/copy.png"}.
+
\section1 Runtime API
Qt API that deals with iterating and reading files has built-in support for
diff --git a/src/corelib/global/q20algorithm.h b/src/corelib/global/q20algorithm.h
index 2918a679e1..f670a5dbee 100644
--- a/src/corelib/global/q20algorithm.h
+++ b/src/corelib/global/q20algorithm.h
@@ -12,9 +12,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. Types and functions defined
-// in this file will behave exactly as their std counterparts. You
-// may use these definitions in your own code, but be aware that we
+// This file is not part of the Qt API. Types and functions defined in this
+// file can reliably be replaced by their std counterparts, once available.
+// You may use these definitions in your own code, but be aware that we
// will remove them once Qt depends on the C++ version that supports
// them in namespace std. There will be NO deprecation warning, the
// definitions will JUST go away.
@@ -27,11 +27,78 @@
QT_BEGIN_NAMESPACE
namespace q20 {
-// like std::is_sorted{,_until} (ie. constexpr)
+// like std::<algorithm> (ie. not ranged, but constexpr)
#ifdef __cpp_lib_constexpr_algorithms
+using std::copy;
+using std::copy_if;
+using std::copy_n;
+using std::fill;
+using std::fill_n;
using std::is_sorted_until;
using std::is_sorted;
+using std::transform;
#else
+template <typename InputIterator, typename OutputIterator>
+constexpr OutputIterator
+copy(InputIterator first, InputIterator last, OutputIterator dest)
+{
+ while (first != last) {
+ *dest = *first;
+ ++first;
+ ++dest;
+ }
+ return dest;
+}
+
+template <typename InputIterator, typename OutputIterator, typename UnaryPredicate>
+constexpr OutputIterator
+copy_if(InputIterator first, InputIterator last, OutputIterator dest, UnaryPredicate pred)
+{
+ while (first != last) {
+ if (pred(*first)) {
+ *dest = *first;
+ ++dest;
+ }
+ ++first;
+ }
+ return dest;
+}
+
+template <typename InputIterator, typename Size, typename OutputIterator>
+constexpr OutputIterator
+copy_n(InputIterator first, Size n, OutputIterator dest)
+{
+ while (n > Size{0}) {
+ *dest = *first;
+ ++first;
+ ++dest;
+ --n;
+ }
+ return dest;
+}
+
+template <typename ForwardIterator, typename Value>
+constexpr void
+fill(ForwardIterator first, ForwardIterator last, const Value &value)
+{
+ while (first != last) {
+ *first = value;
+ ++first;
+ }
+}
+
+template <typename OutputIterator, typename Size, typename Value>
+constexpr OutputIterator
+fill_n(OutputIterator first, Size n, const Value &value)
+{
+ while (n > Size{0}) {
+ *first = value;
+ ++first;
+ --n;
+ }
+ return first;
+}
+
template <typename ForwardIterator, typename BinaryPredicate = std::less<>>
constexpr ForwardIterator
is_sorted_until(ForwardIterator first, ForwardIterator last, BinaryPredicate p = {})
@@ -46,11 +113,27 @@ is_sorted_until(ForwardIterator first, ForwardIterator last, BinaryPredicate p =
}
return first;
}
+
template <typename ForwardIterator, typename BinaryPredicate = std::less<>>
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last, BinaryPredicate p = {})
{
return q20::is_sorted_until(first, last, p) == last;
}
+
+template <typename InputIterator, typename OutputIterator, typename UnaryFunction>
+constexpr OutputIterator
+transform(InputIterator first, InputIterator last, OutputIterator dest, UnaryFunction op)
+{
+ while (first != last) {
+ *dest = op(*first);
+ ++first;
+ ++dest;
+ }
+ return dest;
+}
+
+// binary transform missing on purpose (no users)
+
#endif
}
diff --git a/src/corelib/global/q20functional.h b/src/corelib/global/q20functional.h
index 9584252663..7ba10bd4b1 100644
--- a/src/corelib/global/q20functional.h
+++ b/src/corelib/global/q20functional.h
@@ -11,9 +11,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. Types and functions defined
-// in this file will behave exactly as their std counterparts. You
-// may use these definitions in your own code, but be aware that we
+// This file is not part of the Qt API. Types and functions defined in this
+// file can reliably be replaced by their std counterparts, once available.
+// You may use these definitions in your own code, but be aware that we
// will remove them once Qt depends on the C++ version that supports
// them in namespace std. There will be NO deprecation warning, the
// definitions will JUST go away.
diff --git a/src/corelib/global/q20iterator.h b/src/corelib/global/q20iterator.h
index a7f1cf3cfc..23b6406b64 100644
--- a/src/corelib/global/q20iterator.h
+++ b/src/corelib/global/q20iterator.h
@@ -11,9 +11,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. Types and functions defined
-// in this file will behave exactly as their std counterparts. You
-// may use these definitions in your own code, but be aware that we
+// This file is not part of the Qt API. Types and functions defined in this
+// file can reliably be replaced by their std counterparts, once available.
+// You may use these definitions in your own code, but be aware that we
// will remove them once Qt depends on the C++ version that supports
// them in namespace std. There will be NO deprecation warning, the
// definitions will JUST go away.
diff --git a/src/corelib/global/q23functional.h b/src/corelib/global/q23functional.h
index 5f83df698e..ae8f78a3d0 100644
--- a/src/corelib/global/q23functional.h
+++ b/src/corelib/global/q23functional.h
@@ -10,9 +10,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. Types and functions defined
-// in this file will behave exactly as their std counterparts. You
-// may use these definitions in your own code, but be aware that we
+// This file is not part of the Qt API. Types and functions defined in this
+// file can reliably be replaced by their std counterparts, once available.
+// You may use these definitions in your own code, but be aware that we
// will remove them once Qt depends on the C++ version that supports
// them in namespace std. There will be NO deprecation warning, the
// definitions will JUST go away.
diff --git a/src/corelib/global/qcompare.qdoc b/src/corelib/global/qcompare.qdoc
index e822f40490..33b8f31000 100644
--- a/src/corelib/global/qcompare.qdoc
+++ b/src/corelib/global/qcompare.qdoc
@@ -26,7 +26,7 @@
object is equivalent to the second;
\li \c QPartialOrdering::Greater represents that the first object
- is equivalent to the second;
+ is greater than the second;
\li \c QPartialOrdering::Unordered represents that the first object
is \e{not ordered} with respect to the second.
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index e7d3cb0fc7..4d771ea3b2 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -12,6 +12,7 @@
/*
The compiler, must be one of: (Q_CC_x)
+ COVERITY - Coverity cov-scan
SYM - Digital Mars C/C++ (used to be Symantec C++)
MSVC - Microsoft Visual C/C++, Intel C++ for Windows
BOR - Borland/Turbo C++
@@ -38,6 +39,10 @@
Should be sorted most to least authoritative.
*/
+#if defined(__COVERITY__)
+# define Q_CC_COVERITY
+#endif
+
/* Symantec C++ is now Digital Mars */
#if defined(__DMC__) || defined(__SC__)
# define Q_CC_SYM
@@ -440,6 +445,12 @@
#define QT_HAS_INCLUDE(x) __has_include(x)
#define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x)
+#ifdef __cplusplus
+# if __has_include(<version>) /* remove this check once Integrity, QNX have caught up */
+# include <version>
+# endif
+#endif
+
/*
* C++11 support
*
@@ -480,9 +491,15 @@
* N1653 Q_COMPILER_VARIADIC_MACROS
* N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES __cpp_variadic_templates = 200704
*
- * For any future version of the C++ standard, we use only the SD-6 macro.
- * For full listing, see
- * http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
+ *
+ * For the C++ standards C++14 and C++17, we use only the SD-6 macro.
+ *
+ * For any future version of the C++ standard, we use only the C++20 feature test macro.
+ * For library features, we assume <version> is present (this header includes it).
+ *
+ * For a full listing of feature test macros, see
+ * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations (by macro)
+ * https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros (by C++ version)
*
* C++ extensions:
* Q_COMPILER_RESTRICTED_VLA variable-length arrays, prior to __cpp_runtime_arrays
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index a23dbb53cd..c791c26ac1 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -179,26 +179,35 @@ typedef QFlags<Enum> Flags;
// These are opt-in, for backwards compatibility
#define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \
+[[maybe_unused]] \
constexpr inline Flags operator~(Flags::enum_type e) noexcept \
{ return ~Flags(e); } \
+[[maybe_unused]] \
constexpr inline void operator|(Flags::enum_type f1, int f2) noexcept = delete;
#else
#define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \
+[[maybe_unused]] \
constexpr inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \
{ return QIncompatibleFlag(int(f1) | f2); }
#endif
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 | f1; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) & f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 & f1; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) ^ f2; } \
+[[maybe_unused]] \
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
{ return f2 ^ f1; } \
constexpr inline void operator+(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \
@@ -218,6 +227,7 @@ QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags)
#if __cplusplus > 201702L // assume compilers don't warn if in C++17 mode
// in C++20 mode, provide user-defined operators to override the deprecated operations:
# define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \
+ [[maybe_unused]] \
constexpr inline Ret operator op (LHS lhs, RHS rhs) noexcept \
{ return static_cast<Ret>(qToUnderlying(lhs) op qToUnderlying(rhs)); } \
/* end */
diff --git a/src/corelib/global/qforeach.h b/src/corelib/global/qforeach.h
index 20376b3875..f9dffe2017 100644
--- a/src/corelib/global/qforeach.h
+++ b/src/corelib/global/qforeach.h
@@ -22,13 +22,13 @@ template <typename T>
class QForeachContainer {
Q_DISABLE_COPY(QForeachContainer)
public:
- QForeachContainer(const T &t) : c(t), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
- QForeachContainer(T &&t) : c(std::move(t)), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
+ QForeachContainer(const T &t) : c(t), i(std::as_const(c).begin()), e(std::as_const(c).end()) {}
+ QForeachContainer(T &&t) : c(std::move(t)), i(std::as_const(c).begin()), e(std::as_const(c).end()) {}
QForeachContainer(QForeachContainer &&other)
: c(std::move(other.c)),
- i(qAsConst(c).begin()),
- e(qAsConst(c).end()),
+ i(std::as_const(c).begin()),
+ e(std::as_const(c).end()),
control(std::move(other.control))
{
}
@@ -36,8 +36,8 @@ public:
QForeachContainer &operator=(QForeachContainer &&other)
{
c = std::move(other.c);
- i = qAsConst(c).begin();
- e = qAsConst(c).end();
+ i = std::as_const(c).begin();
+ e = std::as_const(c).end();
control = std::move(other.control);
return *this;
}
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index d2805f52e1..e9a75ba9e8 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -2283,19 +2283,19 @@ static bool readEtcFile(QUnixOSVersion &v, const char *filename,
line.setRawData(ptr, eol - ptr);
if (line.startsWith(idKey)) {
- ptr += idKey.length();
+ ptr += idKey.size();
v.productType = unquote(ptr, eol);
continue;
}
if (line.startsWith(prettyNameKey)) {
- ptr += prettyNameKey.length();
+ ptr += prettyNameKey.size();
v.prettyName = unquote(ptr, eol);
continue;
}
if (line.startsWith(versionKey)) {
- ptr += versionKey.length();
+ ptr += versionKey.size();
v.productVersion = unquote(ptr, eol);
continue;
}
@@ -2332,7 +2332,7 @@ static bool readEtcLsbRelease(QUnixOSVersion &v)
int fd = qt_safe_open(distrorelease, O_RDONLY);
if (fd != -1) {
QT_STATBUF sbuf;
- if (QT_FSTAT(fd, &sbuf) != -1 && sbuf.st_size > v.prettyName.length()) {
+ if (QT_FSTAT(fd, &sbuf) != -1 && sbuf.st_size > v.prettyName.size()) {
// file apparently contains interesting information
QByteArray buffer(sbuf.st_size, Qt::Uninitialized);
buffer.resize(qt_safe_read(fd, buffer.data(), sbuf.st_size));
@@ -3619,6 +3619,14 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept
*/
bool qputenv(const char *varName, const QByteArray &value)
{
+ // protect against non-NUL-terminated QByteArrays:
+ if (!const_cast<QByteArray&>(value).data_ptr()->isMutable()) {
+ QByteArray copy(value);
+ copy.reserve(copy.size() + 1); // ensures NUL termination (and isMutable() even for size==0
+ // (unlike detach()) to avoid infinite recursion)
+ return qputenv(varName, copy);
+ }
+
#if defined(Q_CC_MSVC)
const auto locker = qt_scoped_lock(environmentMutex);
return _putenv_s(varName, value.constData()) == 0;
@@ -3803,8 +3811,9 @@ bool qunsetenv(const char *varName)
Replaces the value of \a obj with \a newValue and returns the old value of \a obj.
This is Qt's implementation of std::exchange(). It differs from std::exchange()
- only in that it is \c constexpr already in C++14, and available on all supported
- compilers.
+ only in that it is \c constexpr already before C++20 and noexcept already before C++23.
+
+ We strongly advise to use std::exchange() when you don't need the C++20 or C++23 variants.
Here is how to use qExchange() to implement move constructors:
\code
@@ -4571,26 +4580,22 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
/*!
\macro Q_DECL_CONSTEXPR
\relates <QtGlobal>
+ \deprecated [6.4] Use the \c constexpr keyword instead.
This macro can be used to declare variable that should be constructed at compile-time,
or an inline function that can be computed at compile-time.
- It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
- otherwise.
-
\sa Q_DECL_RELAXED_CONSTEXPR
*/
/*!
\macro Q_DECL_RELAXED_CONSTEXPR
\relates <QtGlobal>
+ \deprecated [6.4] Use the \c constexpr keyword instead.
This macro can be used to declare an inline function that can be computed
at compile-time according to the relaxed rules from C++14.
- It expands to "constexpr" if your compiler supports C++14 relaxed constant
- expressions, or to nothing otherwise.
-
\sa Q_DECL_CONSTEXPR
*/
@@ -4784,18 +4789,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
\macro Q_DECL_NOTHROW
\relates <QtGlobal>
\since 5.0
+ \deprecated [6.4] Use the \c noexcept keyword instead.
This macro marks a function as never throwing, under no
circumstances. If the function does nevertheless throw, the
behaviour is undefined.
- The macro expands to either "throw()", if that has some benefit on
- the compiler, or to C++11 noexcept, if available, or to nothing
- otherwise.
-
- If you need C++11 noexcept semantics, don't use this macro, use
- Q_DECL_NOEXCEPT/Q_DECL_NOEXCEPT_EXPR instead.
-
\sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR()
*/
@@ -4833,20 +4832,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
\macro Q_DECL_NOEXCEPT
\relates <QtGlobal>
\since 5.0
+ \deprecated [6.4] Use the \c noexcept keyword instead.
This macro marks a function as never throwing. If the function
does nevertheless throw, the behaviour is defined:
std::terminate() is called.
- The macro expands to C++11 noexcept, if available, or to nothing
- otherwise.
-
- If you need the operator version of C++11 noexcept, use
- Q_DECL_NOEXCEPT_EXPR(x).
-
- If you don't need C++11 noexcept semantics, e.g. because your
- function can't possibly throw, don't use this macro, use
- Q_DECL_NOTHROW instead.
\sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR()
*/
@@ -4855,20 +4846,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
\macro Q_DECL_NOEXCEPT_EXPR(x)
\relates <QtGlobal>
\since 5.0
+ \deprecated [6.4] Use the \c noexcept keyword instead.
This macro marks a function as non-throwing if \a x is \c true. If
the function does nevertheless throw, the behaviour is defined:
std::terminate() is called.
- The macro expands to C++11 noexcept(x), if available, or to
- nothing otherwise.
-
- If you need the always-true version of C++11 noexcept, use
- Q_DECL_NOEXCEPT.
-
- If you don't need C++11 noexcept semantics, e.g. because your
- function can't possibly throw, don't use this macro, use
- Q_DECL_NOTHROW instead.
\sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT
*/
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 147933066f..77eb691dad 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -33,46 +33,10 @@
#include <QtCore/qtcore-config.h>
#endif
-/*
- The Qt modules' export macros.
- The options are:
- - defined(QT_STATIC): Qt was built or is being built in static mode
- - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
- If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
- mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
- for the bootstrapped tools.
-*/
-
-#ifdef QT_BOOTSTRAPPED
-# ifdef QT_SHARED
-# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
-# elif !defined(QT_STATIC)
-# define QT_STATIC
-# endif
-#endif
-
-#if defined(QT_SHARED) || !defined(QT_STATIC)
-# ifdef QT_STATIC
-# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
-# endif
-# ifndef QT_SHARED
-# define QT_SHARED
-# endif
-#endif
-
+#include <QtCore/qtconfigmacros.h>
#include <QtCore/qtcoreexports.h>
/*
- The QT_CONFIG macro implements a safe compile time check for features of Qt.
- Features can be in three states:
- 0 or undefined: This will lead to a compile error when testing for it
- -1: The feature is not available
- 1: The feature is available
-*/
-#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
-#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
-
-/*
helper macros to make some simple code work active in Qt 6 or Qt 7 only,
like:
struct QT6_ONLY(Q_CORE_EXPORT) QTrivialClass
@@ -121,7 +85,7 @@
# define QT6_IMPL_NEW_OVERLOAD QT6_ONLY(Qt::Disambiguated_t)
# define QT6_IMPL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_IMPL_NEW_OVERLOAD)
# define QT6_CALL_NEW_OVERLOAD QT6_ONLY(Qt::Disambiguated)
-# define QT6_CALL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT_CALL_NEW_OVERLOAD)
+# define QT6_CALL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_CALL_NEW_OVERLOAD)
#endif
/* These two macros makes it possible to turn the builtin line expander into a
@@ -192,12 +156,6 @@ static_assert(!std::is_convertible_v<std::nullptr_t, bool>,
# define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
#endif
-# include <QtCore/qtnamespacemacros.h>
-
-#if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
-# define QT_LARGEFILE_SUPPORT 64
-#endif
-
#ifndef __ASSEMBLER__
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index d931dfac48..ccbb4b217a 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -534,7 +534,7 @@ QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMo
startIndex = ret.indexOf(u'$', startIndex);
if (startIndex < 0)
break;
- if (ret.length() < startIndex + 3)
+ if (ret.size() < startIndex + 3)
break;
if (ret.at(startIndex + 1) != u'(') {
startIndex++;
@@ -546,7 +546,7 @@ QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMo
auto envVarName = QStringView{ret}.mid(startIndex + 2, endIndex - startIndex - 2);
QString value = QString::fromLocal8Bit(qgetenv(envVarName.toLocal8Bit().constData()));
ret.replace(startIndex, endIndex - startIndex + 1, value);
- startIndex += value.length();
+ startIndex += value.size();
}
config->endGroup();
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 94ec78f382..16755e6e21 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -862,7 +862,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
if (info.isEmpty())
return info;
- int pos;
+ qsizetype pos;
// Skip trailing [with XXX] for templates (gcc), but make
// sure to not affect Objective-C message names.
@@ -892,6 +892,12 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
// Don't know how to parse this function name
return info;
}
+ if (info.indexOf('>', pos) != -1
+ || info.indexOf(':', pos) != -1) {
+ // that wasn't the function argument list.
+ pos = info.size();
+ break;
+ }
// find the beginning of the argument list
--pos;
@@ -909,7 +915,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
info.truncate(++pos);
if (info.at(pos - 1) == ')') {
- if (info.indexOf(operator_call) == pos - (int)strlen(operator_call))
+ if (info.indexOf(operator_call) == pos - qsizetype(strlen(operator_call)))
break;
// this function returns a pointer to a function
@@ -932,19 +938,19 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
if (pos > -1) {
switch (info.at(pos)) {
case ')':
- if (info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1)
+ if (info.indexOf(operator_call) == pos - qsizetype(strlen(operator_call)) + 1)
pos -= 2;
break;
case '<':
- if (info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1)
+ if (info.indexOf(operator_lessThan) == pos - qsizetype(strlen(operator_lessThan)) + 1)
--pos;
break;
case '>':
- if (info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1)
+ if (info.indexOf(operator_greaterThan) == pos - qsizetype(strlen(operator_greaterThan)) + 1)
--pos;
break;
case '=': {
- int operatorLength = (int)strlen(operator_lessThanEqual);
+ auto operatorLength = qsizetype(strlen(operator_lessThanEqual));
if (info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1)
pos -= 2;
else if (info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1)
@@ -988,7 +994,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
break;
// find the matching close
- int end = pos;
+ qsizetype end = pos;
templatecount = 1;
--pos;
while (pos && templatecount) {
@@ -1151,9 +1157,9 @@ void QMessagePattern::setPattern(const QString &pattern)
tokens[i] = qthreadptrTokenC;
else if (lexeme.startsWith(QLatin1StringView(timeTokenC))) {
tokens[i] = timeTokenC;
- int spaceIdx = lexeme.indexOf(QChar::fromLatin1(' '));
+ qsizetype spaceIdx = lexeme.indexOf(QChar::fromLatin1(' '));
if (spaceIdx > 0)
- timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.length() - spaceIdx - 2));
+ timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.size() - spaceIdx - 2));
else
timeArgs.append(QString());
} else if (lexeme.startsWith(QLatin1StringView(backtraceTokenC))) {
@@ -1209,11 +1215,8 @@ void QMessagePattern::setPattern(const QString &pattern)
.arg(lexeme);
}
} else {
- char *literal = new char[lexeme.size() + 1];
- strncpy(literal, lexeme.toLatin1().constData(), lexeme.size());
- literal[lexeme.size()] = '\0';
- literalsVar.emplace_back(literal);
- tokens[i] = literal;
+ using UP = std::unique_ptr<char[]>;
+ tokens[i] = literalsVar.emplace_back(UP(qstrdup(lexeme.toLatin1().constData()))).get();
}
}
if (nestedIfError)
@@ -1302,7 +1305,7 @@ static QStringList backtraceFramesForLogMessage(int frameCount)
// use dladdr() instead of backtrace_symbols()
QString cachedLibrary;
const char *cachedFname = nullptr;
- auto decodeFrame = [&](const void *addr) -> DecodedFrame {
+ auto decodeFrame = [&](void *addr) -> DecodedFrame {
Dl_info info;
if (!dladdr(addr, &info))
return {};
@@ -2040,9 +2043,12 @@ void qErrnoWarning(int code, const char *msg, ...)
\row \li \c{%{backtrace [depth=N] [separator="..."]}} \li A backtrace with the number of frames
specified by the optional \c depth parameter (defaults to 5), and separated by the optional
\c separator parameter (defaults to "|").
+
This expansion is available only on some platforms (currently only platfoms using glibc).
Names are only known for exported functions. If you want to see the name of every function
- in your application, use \c{QMAKE_LFLAGS += -rdynamic}.
+ in your application, make sure your application is compiled and linked with \c{-rdynamic},
+ or an equivalent of it.
+
When reading backtraces, take into account that frames might be missing due to inlining or
tail call optimization.
\endtable
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 23e3e9736b..37d5c1e1f9 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2202,11 +2202,17 @@
you call QWidget::activateWindow() manually).
\value FramelessWindowHint Produces a borderless window.
- The user cannot move or resize a borderless window via the window
- system. On X11, the result of the flag is dependent on the window manager and its
+
+ On X11, the result of the flag is dependent on the window manager and its
ability to understand Motif and/or NETWM hints. Most existing
modern window managers can handle this.
+ \note If the window manager relies on the frame to interactively manipulate
+ the window, the user can no longer move or resize the window via the window
+ system, but this side effect should not be relied on. To produce a fixed
+ size window that can not be resized, please set QWindow::setMinimumSize()
+ and QWindow::setMaximumSize() to the same size.
+
\value NoDropShadowWindowHint Disables window drop shadow on supporting platforms.
The \c CustomizeWindowHint flag is used to enable customization of
diff --git a/src/corelib/global/qnumeric.cpp b/src/corelib/global/qnumeric.cpp
index 544d3e17b8..50b850e29d 100644
--- a/src/corelib/global/qnumeric.cpp
+++ b/src/corelib/global/qnumeric.cpp
@@ -316,4 +316,35 @@ Q_CORE_EXPORT quint64 qFloatDistance(double a, double b)
This can be faster than calling the version with only variable arguments.
*/
+template <typename T> static constexpr T max = std::numeric_limits<T>::max();
+template <typename T> static constexpr T min = std::numeric_limits<T>::min();
+
+static_assert(qt_saturate<short>(max<unsigned>) == max<short>);
+static_assert(qt_saturate<int>(max<unsigned>) == max<int>);
+static_assert(qt_saturate<qint64>(max<unsigned>) == qint64(max<unsigned>));
+
+static_assert(qt_saturate<short>(max<int>) == max<short>);
+static_assert(qt_saturate<unsigned>(max<int>) == unsigned(max<int>));
+static_assert(qt_saturate<qint64>(max<int>) == qint64(max<int>));
+
+static_assert(qt_saturate<short>(max<qint64>) == max<short>);
+static_assert(qt_saturate<int>(max<qint64>) == max<int>);
+static_assert(qt_saturate<unsigned>(max<qint64>) == max<unsigned>);
+static_assert(qt_saturate<quint64>(max<qint64>) == quint64(max<qint64>));
+
+static_assert(qt_saturate<short>(max<quint64>) == max<short>);
+static_assert(qt_saturate<int>(max<quint64>) == max<int>);
+static_assert(qt_saturate<unsigned>(max<quint64>) == max<unsigned>);
+static_assert(qt_saturate<qint64>(max<quint64>) == max<qint64>);
+
+static_assert(qt_saturate<short>(min<int>) == min<short>);
+static_assert(qt_saturate<qint64>(min<int>) == qint64(min<int>));
+static_assert(qt_saturate<unsigned>(min<int>) == 0);
+static_assert(qt_saturate<quint64>(min<int>) == 0);
+
+static_assert(qt_saturate<short>(min<qint64>) == min<short>);
+static_assert(qt_saturate<int>(min<qint64>) == min<int>);
+static_assert(qt_saturate<unsigned>(min<qint64>) == 0);
+static_assert(qt_saturate<quint64>(min<qint64>) == 0);
+
QT_END_NAMESPACE
diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h
index d3a74a33e5..337f1e8118 100644
--- a/src/corelib/global/qnumeric.h
+++ b/src/corelib/global/qnumeric.h
@@ -312,6 +312,8 @@ template <typename T, T V2> bool qMulOverflow(T v1, std::integral_constant<T, V2
template <auto V2, typename T> bool qMulOverflow(T v1, T *r)
{
+ if constexpr (V2 == 2)
+ return qAddOverflow(v1, v1, r);
return qMulOverflow(v1, std::integral_constant<T, V2>{}, r);
}
diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h
index 7c65b67b7a..f5beb4d38d 100644
--- a/src/corelib/global/qnumeric_p.h
+++ b/src/corelib/global/qnumeric_p.h
@@ -314,6 +314,41 @@ template <auto V2, typename T> bool mul_overflow(T v1, T *r)
}
#endif // Q_CLANG_QDOC
+/*
+ Safely narrows \a x to \c{To}. Let \c L be
+ \c{std::numeric_limit<To>::min()} and \c H be \c{std::numeric_limit<To>::max()}.
+
+ If \a x is less than L, returns L. If \a x is greater than H,
+ returns H. Otherwise, returns \c{To(x)}.
+*/
+template <typename To, typename From>
+static constexpr auto qt_saturate(From x)
+{
+ static_assert(std::is_integral_v<To>);
+ static_assert(std::is_integral_v<From>);
+
+ [[maybe_unused]]
+ constexpr auto Lo = (std::numeric_limits<To>::min)();
+ constexpr auto Hi = (std::numeric_limits<To>::max)();
+
+ if constexpr (std::is_signed_v<From> == std::is_signed_v<To>) {
+ // same signedness, we can accept regular integer conversion rules
+ return x < Lo ? Lo :
+ x > Hi ? Hi :
+ /*else*/ To(x);
+ } else {
+ if constexpr (std::is_signed_v<From>) { // ie. !is_signed_v<To>
+ if (x < From{0})
+ return To{0};
+ }
+
+ // from here on, x >= 0
+ using FromU = std::make_unsigned_t<From>;
+ using ToU = std::make_unsigned_t<To>;
+ return FromU(x) > ToU(Hi) ? Hi : To(x); // assumes Hi >= 0
+ }
+}
+
QT_END_NAMESPACE
#endif // QNUMERIC_P_H
diff --git a/src/corelib/global/qoperatingsystemversion.cpp b/src/corelib/global/qoperatingsystemversion.cpp
index a89cfa88d2..e02b0fadc9 100644
--- a/src/corelib/global/qoperatingsystemversion.cpp
+++ b/src/corelib/global/qoperatingsystemversion.cpp
@@ -438,6 +438,13 @@ const QOperatingSystemVersion QOperatingSystemVersion::Windows10 =
*/
/*!
+ \variable QOperatingSystemVersion::Windows10_22H2
+ \brief a version corresponding to Windows 10 October 2022 Update
+ Version 22H2 (version 10.0.19045).
+ \since 6.5
+ */
+
+/*!
\variable QOperatingSystemVersion::Windows11
\brief a version corresponding to the initial release of Windows 11
(version 10.0.22000).
@@ -514,24 +521,11 @@ const QOperatingSystemVersion QOperatingSystemVersion::MacOSCatalina =
/*!
\variable QOperatingSystemVersion::MacOSBigSur
- \brief a version corresponding to macOS Big Sur
-
- The actual version number depends on whether the application was built
- using the Xcode 12 SDK. If it was, the version number corresponds
- to macOS 11.0. If not it will correspond to macOS 10.16.
-
- By comparing QOperatingSystemVersion::current() to this constant
- you will always end up comparing to the right version number.
+ \brief a version corresponding to macOS Big Sur (version 11).
\since 6.0
*/
-const QOperatingSystemVersion QOperatingSystemVersion::MacOSBigSur = [] {
-#if defined(Q_OS_DARWIN)
- if (QMacVersion::buildSDK(QMacVersion::ApplicationBinary) >= QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 10, 16))
- return QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 11, 0);
- else
-#endif
- return QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 10, 16);
-}();
+const QOperatingSystemVersion QOperatingSystemVersion::MacOSBigSur =
+ QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 11, 0);
/*!
\variable QOperatingSystemVersion::MacOSMonterey
@@ -542,6 +536,12 @@ const QOperatingSystemVersion QOperatingSystemVersion::MacOSMonterey =
QOperatingSystemVersion(QOperatingSystemVersion::MacOS, 12, 0);
/*!
+ \variable QOperatingSystemVersion::MacOSVentura
+ \brief a version corresponding to macOS Ventura (version 13).
+ \since 6.4
+*/
+
+/*!
\variable QOperatingSystemVersion::AndroidJellyBean
\brief a version corresponding to Android Jelly Bean (version 4.1, API level 16).
\since 5.9
diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h
index 5fcc3411de..558a19759f 100644
--- a/src/corelib/global/qoperatingsystemversion.h
+++ b/src/corelib/global/qoperatingsystemversion.h
@@ -165,12 +165,8 @@ public:
static constexpr QOperatingSystemVersionBase MacOSHighSierra { QOperatingSystemVersionBase::MacOS, 10, 13 };
static constexpr QOperatingSystemVersionBase MacOSMojave { QOperatingSystemVersionBase::MacOS, 10, 14 };
static constexpr QOperatingSystemVersionBase MacOSCatalina { QOperatingSystemVersionBase::MacOS, 10, 15 };
-#if !defined(Q_OS_DARWIN) || QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_11_0)
static constexpr QOperatingSystemVersionBase MacOSBigSur = { QOperatingSystemVersionBase::MacOS, 11, 0 };
static constexpr QOperatingSystemVersionBase MacOSMonterey = { QOperatingSystemVersionBase::MacOS, 12, 0 };
-#else // ### Qt 7: Verify the assumption
-# error Either you are using an outdated SDK or my assumption that Qt7 would require at least 11.0 was wrong
-#endif
static constexpr QOperatingSystemVersionBase AndroidJellyBean { QOperatingSystemVersionBase::Android, 4, 1 };
static constexpr QOperatingSystemVersionBase AndroidJellyBean_MR1 { QOperatingSystemVersionBase::Android, 4, 2 };
@@ -195,10 +191,13 @@ public:
static constexpr QOperatingSystemVersionBase Windows10_20H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19042 };
static constexpr QOperatingSystemVersionBase Windows10_21H1 { QOperatingSystemVersionBase::Windows, 10, 0, 19043 };
static constexpr QOperatingSystemVersionBase Windows10_21H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19044 };
+ static constexpr QOperatingSystemVersionBase Windows10_22H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19045 };
static constexpr QOperatingSystemVersionBase Windows11 { QOperatingSystemVersionBase::Windows, 10, 0, 22000 };
static constexpr QOperatingSystemVersionBase Windows11_21H2 = Windows11;
static constexpr QOperatingSystemVersionBase Windows11_22H2 { QOperatingSystemVersionBase::Windows, 10, 0, 22621 };
+ static constexpr QOperatingSystemVersionBase MacOSVentura { QOperatingSystemVersionBase::MacOS, 13, 0 };
+
constexpr QOperatingSystemVersion(const QOperatingSystemVersionBase &osversion)
: QOperatingSystemVersionBase(osversion) {}
diff --git a/src/corelib/global/qoperatingsystemversion_darwin.mm b/src/corelib/global/qoperatingsystemversion_darwin.mm
index 6581244821..f8d9fbd027 100644
--- a/src/corelib/global/qoperatingsystemversion_darwin.mm
+++ b/src/corelib/global/qoperatingsystemversion_darwin.mm
@@ -2,19 +2,56 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qoperatingsystemversion_p.h"
+
#import <Foundation/Foundation.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qversionnumber.h>
+
+#if !defined(QT_BOOTSTRAPPED)
+#include <QtCore/qprocess.h>
+#endif
+
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
QOperatingSystemVersionBase QOperatingSystemVersionBase::current_impl()
{
NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
- QOperatingSystemVersionBase v;
- v.m_os = currentType();
- v.m_major = osv.majorVersion;
- v.m_minor = osv.minorVersion;
- v.m_micro = osv.patchVersion;
- return v;
+ QVersionNumber versionNumber(osv.majorVersion, osv.minorVersion, osv.patchVersion);
+
+ if (versionNumber.majorVersion() == 10 && versionNumber.minorVersion() >= 16) {
+ // The process is running in system version compatibility mode,
+ // due to the executable being built against a pre-macOS 11 SDK.
+ // This might happen even if we require a more recent SDK for
+ // building Qt applications, as the Qt 'app' might be a plugin
+ // hosted inside a host that used an earlier SDK. But, since we
+ // require a recent SDK for the Qt app itself, the application
+ // should be prepared for versions numbers beyond 10, and we can
+ // resolve the real version number here.
+#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(process)
+ QProcess sysctl;
+ QProcessEnvironment nonCompatEnvironment;
+ nonCompatEnvironment.insert("SYSTEM_VERSION_COMPAT"_L1, "0"_L1);
+ sysctl.setProcessEnvironment(nonCompatEnvironment);
+ sysctl.start("/usr/sbin/sysctl"_L1, QStringList() << "-b"_L1 << "kern.osproductversion"_L1);
+ if (sysctl.waitForFinished()) {
+ auto versionString = QString::fromLatin1(sysctl.readAll());
+ auto nonCompatSystemVersion = QVersionNumber::fromString(versionString);
+ if (!nonCompatSystemVersion.isNull())
+ versionNumber = nonCompatSystemVersion;
+ }
+#endif
+ }
+
+ QOperatingSystemVersionBase operatingSystemVersion;
+ operatingSystemVersion.m_os = currentType();
+ operatingSystemVersion.m_major = versionNumber.majorVersion();
+ operatingSystemVersion.m_minor = versionNumber.minorVersion();
+ operatingSystemVersion.m_micro = versionNumber.microVersion();
+
+ return operatingSystemVersion;
}
QT_END_NAMESPACE
diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h
index fb93a7d06b..f18cbf328b 100644
--- a/src/corelib/global/qprocessordetection.h
+++ b/src/corelib/global/qprocessordetection.h
@@ -291,7 +291,7 @@
*/
#elif defined(__sparc__)
# define Q_PROCESSOR_SPARC
-# if defined(__sparc_v9__)
+# if defined(__sparc_v9__) || defined(__sparcv9)
# define Q_PROCESSOR_SPARC_V9
# endif
# if defined(__sparc64__)
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp
index b276f9445f..c1c2792736 100644
--- a/src/corelib/global/qrandom.cpp
+++ b/src/corelib/global/qrandom.cpp
@@ -647,7 +647,7 @@ inline QRandomGenerator::SystemGenerator &QRandomGenerator::SystemGenerator::sel
\fn bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
\relates QRandomGenerator
- Returns true if the two the two engines \a rng1 and \a rng2 are at the same
+ Returns true if the two engines \a rng1 and \a rng2 are at the same
state or if they are both reading from the operating system facilities,
false otherwise.
*/
@@ -655,7 +655,7 @@ inline QRandomGenerator::SystemGenerator &QRandomGenerator::SystemGenerator::sel
/*!
\fn bool QRandomGenerator::operator!=(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
- Returns \c true if the two the two engines \a rng1 and \a rng2 are at
+ Returns \c true if the two engines \a rng1 and \a rng2 are at
different states or if one of them is reading from the operating system
facilities and the other is not, \c false otherwise.
*/
diff --git a/src/corelib/global/qsimd.h b/src/corelib/global/qsimd.h
index 87e9d0d098..6ed7821e26 100644
--- a/src/corelib/global/qsimd.h
+++ b/src/corelib/global/qsimd.h
@@ -77,9 +77,11 @@
# ifdef __AVX2__
// MSVC defines __AVX2__ with /arch:AVX2
# define __F16C__ 1
+# define __RDRND__ 1
# define __FMA__ 1
# define __BMI__ 1
# define __BMI2__ 1
+# define __MOVBE__ 1
# define __LZCNT__ 1
# endif
// Starting with /arch:AVX512, MSVC defines all the macros
diff --git a/src/corelib/global/qsimd_p.h b/src/corelib/global/qsimd_p.h
index 1feedbbb23..64ba527d2c 100644
--- a/src/corelib/global/qsimd_p.h
+++ b/src/corelib/global/qsimd_p.h
@@ -206,14 +206,15 @@ asm(
// The Intel Core 4th generation was codenamed "Haswell" and introduced AVX2,
// BMI1, BMI2, FMA, LZCNT, MOVBE, which makes it a good divider for a
// sub-target for us. The first AMD processor with AVX2 support (Zen) has the
-// same features. This feature set was chosen as the version 3 of the x86-64
-// ISA (x86-64-v3) and is supported by GCC and Clang.
+// same features, but had already introduced BMI1 in the previous generation.
+// This feature set was chosen as the version 3 of the x86-64 ISA (x86-64-v3)
+// and is supported by GCC and Clang.
//
// macOS's fat binaries support the "x86_64h" sub-architecture and the GNU libc
// ELF loader also supports a "haswell/" subdir (e.g., /usr/lib/haswell).
-# define ARCH_HASWELL_MACROS (__AVX2__ + __BMI__ + __BMI2__ + __F16C__ + __FMA__ + __LZCNT__)
+# define ARCH_HASWELL_MACROS (__AVX2__ + __FMA__)
# if ARCH_HASWELL_MACROS != 0
-# if ARCH_HASWELL_MACROS != 6
+# if ARCH_HASWELL_MACROS != 2
# error "Please enable all x86-64-v3 extensions; you probably want to use -march=haswell or -march=x86-64-v3 instead of -mavx2"
# endif
static_assert(ARCH_HASWELL_MACROS, "Undeclared identifiers indicate which features are missing.");
@@ -223,8 +224,10 @@ static_assert(ARCH_HASWELL_MACROS, "Undeclared identifiers indicate which featur
// x86-64 sub-architecture version 4
//
-// Similar to the above, x86-64-v4 marches the AVX512 variant of the Intel Core
-// 6th generation (codename "Skylake").
+// Similar to the above, x86-64-v4 matches the AVX512 variant of the Intel Core
+// 6th generation (codename "Skylake"). AMD Zen4 is the their first processor
+// with AVX512 support and it includes all of these too.
+//
# define ARCH_SKX_MACROS (__AVX512F__ + __AVX512BW__ + __AVX512CD__ + __AVX512DQ__ + __AVX512VL__)
# if ARCH_SKX_MACROS != 0
# if ARCH_SKX_MACROS != 5
@@ -346,12 +349,16 @@ Q_CORE_EXPORT uint64_t QT_MANGLE_NAMESPACE(qDetectCpuFeatures)();
static inline uint64_t qCpuFeatures()
{
+#ifdef QT_BOOTSTRAPPED
+ return qCompilerCpuFeatures; // no detection
+#else
quint64 features = atomic_load_explicit(QT_MANGLE_NAMESPACE(qt_cpu_features), memory_order_relaxed);
if (!QT_SUPPORTS_INIT_PRIORITY) {
if (Q_UNLIKELY(features == 0))
features = QT_MANGLE_NAMESPACE(qDetectCpuFeatures)();
}
return features;
+#endif
}
#define qCpuHasFeature(feature) (((qCompilerCpuFeatures & CpuFeature ## feature) == CpuFeature ## feature) \
diff --git a/src/corelib/global/qtnamespacemacros.h b/src/corelib/global/qtconfigmacros.h
index e364bbd32f..18eb986414 100644
--- a/src/corelib/global/qtnamespacemacros.h
+++ b/src/corelib/global/qtconfigmacros.h
@@ -1,8 +1,45 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#ifndef QTNAMESPACEMACROS_H
-#define QTNAMESPACEMACROS_H
+#ifndef QTCONFIGMACROS_H
+#define QTCONFIGMACROS_H
+
+/*
+ The Qt modules' export macros.
+ The options are:
+ - defined(QT_STATIC): Qt was built or is being built in static mode
+ - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
+ If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
+ mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
+ for the bootstrapped tools.
+*/
+
+#ifdef QT_BOOTSTRAPPED
+# ifdef QT_SHARED
+# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
+# elif !defined(QT_STATIC)
+# define QT_STATIC
+# endif
+#endif
+
+#if defined(QT_SHARED) || !defined(QT_STATIC)
+# ifdef QT_STATIC
+# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
+# endif
+# ifndef QT_SHARED
+# define QT_SHARED
+# endif
+#endif
+
+/*
+ The QT_CONFIG macro implements a safe compile time check for features of Qt.
+ Features can be in three states:
+ 0 or undefined: This will lead to a compile error when testing for it
+ -1: The feature is not available
+ 1: The feature is available
+*/
+#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
+#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
// valid for both C and C++
#define QT_MANGLE_NAMESPACE0(x) x
@@ -64,7 +101,7 @@ namespace QT_NAMESPACE {}
This expands to a "using QT_NAMESPACE" also in _header files_.
It is the only way the feature can be used without too much
pain, but if people _really_ do not want it they can add
- DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
+ QT_NO_USING_NAMESPACE to their build configuration.
*/
QT_USE_NAMESPACE
# endif
@@ -86,4 +123,4 @@ namespace QT_NAMESPACE {}
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
-#endif /* QTNAMESPACEMACROS_H */
+#endif /* QTCONFIGMACROS_H */
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h
index 1938967a91..1b9381321e 100644
--- a/src/corelib/global/qtypeinfo.h
+++ b/src/corelib/global/qtypeinfo.h
@@ -81,6 +81,12 @@ public:
static constexpr bool isIntegral = false;
};
+// QTypeInfo for std::pair:
+// std::pair is spec'ed to be struct { T1 first; T2 second; }, so, unlike tuple<>,
+// we _can_ specialize QTypeInfo for pair<>:
+template <class T1, class T2>
+class QTypeInfo<std::pair<T1, T2>> : public QTypeInfoMerger<std::pair<T1, T2>, T1, T2> {};
+
#define Q_DECLARE_MOVABLE_CONTAINER(CONTAINER) \
template <typename ...T> \
class QTypeInfo<CONTAINER<T...>> \
@@ -129,7 +135,7 @@ public: \
enum { \
isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !std::is_trivial_v<TYPE>, \
isRelocatable = !isComplex || ((FLAGS) & Q_RELOCATABLE_TYPE) || qIsRelocatable<TYPE>, \
- isPointer = false, \
+ isPointer = std::is_pointer_v< TYPE >, \
isIntegral = std::is_integral< TYPE >::value, \
}; \
}
diff --git a/src/corelib/global/qversiontagging.h b/src/corelib/global/qversiontagging.h
index 4e0eb68bbd..e64cae1d87 100644
--- a/src/corelib/global/qversiontagging.h
+++ b/src/corelib/global/qversiontagging.h
@@ -73,7 +73,7 @@ struct QVersionTag
};
}
-#if defined(QT_BUILD_CORE_LIB) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC)
+#if !defined(QT_NO_VERSION_TAGGING) && (defined(QT_BUILD_CORE_LIB) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC))
// don't make tags in QtCore, bootstrapped systems or if the user asked not to
# define QT_NO_VERSION_TAGGING
#endif
diff --git a/src/corelib/global/qxpfunctional.h b/src/corelib/global/qxpfunctional.h
index 67350c56ed..9657059753 100644
--- a/src/corelib/global/qxpfunctional.h
+++ b/src/corelib/global/qxpfunctional.h
@@ -9,9 +9,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. Types and functions defined
-// in this file will behave exactly as their std counterparts. You
-// may use these definitions in your own code, but be aware that we
+// This file is not part of the Qt API. Types and functions defined in this
+// file can reliably be replaced by their std counterparts, once available.
+// You may use these definitions in your own code, but be aware that we
// will remove them once Qt depends on the C++ version that supports
// them in namespace std. There will be NO deprecation warning, the
// definitions will JUST go away.
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp
index c8f21c5b4c..7eed16d9dd 100644
--- a/src/corelib/io/qabstractfileengine.cpp
+++ b/src/corelib/io/qabstractfileengine.cpp
@@ -123,20 +123,17 @@ QAbstractFileEngineHandler::~QAbstractFileEngineHandler()
*/
QAbstractFileEngine *qt_custom_file_engine_handler_create(const QString &path)
{
- QAbstractFileEngine *engine = nullptr;
-
if (qt_file_engine_handlers_in_use.loadRelaxed()) {
QReadLocker locker(fileEngineHandlerMutex());
// check for registered handlers that can load the file
- QAbstractFileEngineHandlerList *handlers = fileEngineHandlers();
- for (int i = 0; i < handlers->size(); i++) {
- if ((engine = handlers->at(i)->create(path)))
- break;
+ for (QAbstractFileEngineHandler *handler : std::as_const(*fileEngineHandlers())) {
+ if (QAbstractFileEngine *engine = handler->create(path))
+ return engine;
}
}
- return engine;
+ return nullptr;
}
/*!
diff --git a/src/corelib/io/qabstractfileengine_p.h b/src/corelib/io/qabstractfileengine_p.h
index 9982568725..04ad782763 100644
--- a/src/corelib/io/qabstractfileengine_p.h
+++ b/src/corelib/io/qabstractfileengine_p.h
@@ -206,7 +206,7 @@ public:
virtual QString currentFileName() const = 0;
virtual QFileInfo currentFileInfo() const;
- QString currentFilePath() const;
+ virtual QString currentFilePath() const;
protected:
enum EntryInfoType {
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index c244dacab3..36d51822df 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -277,6 +277,10 @@ void QBuffer::setData(const QByteArray &data)
/*!
\reimp
+
+ Unlike QFile, opening a QBuffer QIODevice::WriteOnly does not truncate it.
+ However, pos() is set to 0. Use QIODevice::Append or QIODevice::Truncate to
+ change either behavior.
*/
bool QBuffer::open(OpenMode flags)
{
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 524a04456a..0afbb374fa 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -24,15 +24,16 @@ using QtMiscUtils::fromHex;
/*
Returns a human readable representation of the first \a maxSize
- characters in \a data.
+ characters in \a data. The size, \a len, is a 64-bit quantity to
+ avoid truncation due to implicit conversions in callers.
*/
-QByteArray QtDebugUtils::toPrintable(const char *data, int len, int maxSize)
+QByteArray QtDebugUtils::toPrintable(const char *data, qint64 len, qsizetype maxSize)
{
if (!data)
return "(null)";
QByteArray out;
- for (int i = 0; i < qMin(len, maxSize); ++i) {
+ for (qsizetype i = 0; i < qMin(len, maxSize); ++i) {
char c = data[i];
if (isprint(c)) {
out += c;
@@ -202,7 +203,7 @@ static inline bool isPrintable(uchar c)
{ return c >= ' ' && c < 0x7f; }
template <typename Char>
-static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true)
+static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true)
{
QChar quote(u'"');
d->write(&quote, 1);
@@ -222,7 +223,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in
if (sizeof(Char) == sizeof(QChar)) {
// Surrogate characters are category Cs (Other_Surrogate), so isPrintable = false for them
- int runLength = 0;
+ qsizetype runLength = 0;
while (p + runLength != end &&
isPrintable(p[runLength]) && p[runLength] != '\\' && p[runLength] != '"')
++runLength;
@@ -319,12 +320,12 @@ void QDebug::putString(const QChar *begin, size_t length)
if (stream->noQuotes) {
// no quotes, write the string directly too (no pretty-printing)
// this respects the QTextStream state, though
- stream->ts.d_ptr->putString(begin, int(length));
+ stream->ts.d_ptr->putString(begin, qsizetype(length));
} else {
// we'll reset the QTextStream formatting mechanisms, so save the state
QDebugStateSaver saver(*this);
stream->ts.d_ptr->params.reset();
- putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), int(length));
+ putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), length);
}
}
@@ -337,14 +338,15 @@ void QDebug::putByteArray(const char *begin, size_t length, Latin1Content conten
if (stream->noQuotes) {
// no quotes, write the string directly too (no pretty-printing)
// this respects the QTextStream state, though
- QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, int(length)) : QString::fromUtf8(begin, int(length));
+ QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, qsizetype(length))
+ : QString::fromUtf8(begin, qsizetype(length));
stream->ts.d_ptr->putString(string);
} else {
// we'll reset the QTextStream formatting mechanisms, so save the state
QDebugStateSaver saver(*this);
stream->ts.d_ptr->params.reset();
putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const uchar *>(begin),
- int(length), content == ContainsLatin1);
+ length, content == ContainsLatin1);
}
}
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 62999d8011..ad01a3dcd8 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -106,7 +106,7 @@ public:
inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); }
inline QDebug &operator<<(const char16_t *t) { stream->ts << QStringView(t); return maybeSpace(); }
- inline QDebug &operator<<(const QString & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
+ inline QDebug &operator<<(const QString & t) { putString(t.constData(), size_t(t.size())); return maybeSpace(); }
inline QDebug &operator<<(QStringView s) { putString(s.data(), size_t(s.size())); return maybeSpace(); }
inline QDebug &operator<<(QUtf8StringView s) { putByteArray(reinterpret_cast<const char*>(s.data()), s.size(), ContainsBinary); return maybeSpace(); }
inline QDebug &operator<<(QLatin1StringView t) { putByteArray(t.latin1(), t.size(), ContainsLatin1); return maybeSpace(); }
@@ -292,7 +292,7 @@ inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QContiguousCache
{
const QDebugStateSaver saver(debug);
debug.nospace() << "QContiguousCache(";
- for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
+ for (qsizetype i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
debug << cache[i];
if (i != cache.lastIndex())
debug << ", ";
diff --git a/src/corelib/io/qdebug_p.h b/src/corelib/io/qdebug_p.h
index 1dead0f47d..810fc3b4b6 100644
--- a/src/corelib/io/qdebug_p.h
+++ b/src/corelib/io/qdebug_p.h
@@ -25,7 +25,7 @@ QT_BEGIN_NAMESPACE
namespace QtDebugUtils {
-Q_CORE_EXPORT QByteArray toPrintable(const char *data, int len, int maxSize);
+Q_CORE_EXPORT QByteArray toPrintable(const char *data, qint64 len, qsizetype maxSize);
// inline helpers for formatting basic classes.
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 09315f9afe..eb55696ccf 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -57,13 +57,13 @@ enum {
};
// Return the length of the root part of an absolute path, for use by cleanPath(), cd().
-static int rootLength(const QString &name, bool allowUncPaths)
+static qsizetype rootLength(QStringView name, bool allowUncPaths)
{
- const int len = name.length();
+ const qsizetype len = name.size();
// starts with double slash
if (allowUncPaths && name.startsWith("//"_L1)) {
// Server name '//server/path' is part of the prefix.
- const int nextSlash = name.indexOf(u'/', 2);
+ const qsizetype nextSlash = name.indexOf(u'/', 2);
return nextSlash >= 0 ? nextSlash + 1 : len;
}
#if defined(Q_OS_WIN)
@@ -132,7 +132,7 @@ bool QDirPrivate::exists() const
inline QChar QDirPrivate::getFilterSepChar(const QString &nameFilter)
{
QChar sep(u';');
- int i = nameFilter.indexOf(sep, 0);
+ qsizetype i = nameFilter.indexOf(sep, 0);
if (i == -1 && nameFilter.indexOf(u' ', 0) != -1)
sep = QChar(u' ');
return sep;
@@ -153,12 +153,12 @@ inline void QDirPrivate::setPath(const QString &path)
{
QString p = QDir::fromNativeSeparators(path);
if (p.endsWith(u'/')
- && p.length() > 1
+ && p.size() > 1
#if defined(Q_OS_WIN)
&& (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter()))
#endif
) {
- p.truncate(p.length() - 1);
+ p.truncate(p.size() - 1);
}
dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath());
@@ -288,7 +288,7 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
QStringList *names, QFileInfoList *infos)
{
// names and infos are always empty lists or 0 here
- int n = l.size();
+ qsizetype n = l.size();
if (n > 0) {
if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) {
if (infos)
@@ -299,16 +299,16 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
}
} else {
QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]);
- for (int i = 0; i < n; ++i)
+ for (qsizetype i = 0; i < n; ++i)
si[i].item = l.at(i);
std::sort(si.data(), si.data() + n, QDirSortItemComparator(sort));
// put them back in the list(s)
if (infos) {
- for (int i = 0; i < n; ++i)
+ for (qsizetype i = 0; i < n; ++i)
infos->append(si[i].item);
}
if (names) {
- for (int i = 0; i < n; ++i)
+ for (qsizetype i = 0; i < n; ++i)
names->append(si[i].item.fileName());
}
}
@@ -507,6 +507,10 @@ inline void QDirPrivate::initFileEngine()
\snippet qdir-listfiles/main.cpp 0
+ \section1 Platform Specific Issues
+
+ \include android-content-uri-limitations.qdocinc
+
\sa QFileInfo, QFile, QFileDialog, QCoreApplication::applicationDirPath(), {Find Files Example}
*/
@@ -611,7 +615,7 @@ void QDir::setPath(const QString &path)
*/
QString QDir::path() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return d->dirEntry.filePath();
}
@@ -625,9 +629,13 @@ QString QDir::path() const
*/
QString QDir::absolutePath() const
{
- const QDirPrivate* d = d_ptr.constData();
- d->resolveAbsoluteEntry();
- return d->absoluteDirEntry.filePath();
+ Q_D(const QDir);
+ if (!d->fileEngine) {
+ d->resolveAbsoluteEntry();
+ return d->absoluteDirEntry.filePath();
+ }
+
+ return d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
}
/*!
@@ -648,7 +656,7 @@ QString QDir::absolutePath() const
*/
QString QDir::canonicalPath() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (!d->fileEngine) {
QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
return answer.filePath();
@@ -669,17 +677,19 @@ QString QDir::canonicalPath() const
*/
QString QDir::dirName() const
{
- const QDirPrivate* d = d_ptr.constData();
- return d->dirEntry.fileName();
+ Q_D(const QDir);
+ if (!d_ptr->fileEngine)
+ return d->dirEntry.fileName();
+ return d->fileEngine->fileName(QAbstractFileEngine::BaseName);
}
#ifdef Q_OS_WIN
-static int drivePrefixLength(const QString &path)
+static qsizetype drivePrefixLength(QStringView path)
{
// Used to extract path's drive for use as prefix for an "absolute except for drive" path
- const int size = path.length();
- int drive = 2; // length of drive prefix
+ const qsizetype size = path.size();
+ qsizetype drive = 2; // length of drive prefix
if (size > 1 && path.at(1).unicode() == ':') {
if (Q_UNLIKELY(!path.at(0).isLetter()))
return 0;
@@ -691,7 +701,7 @@ static int drivePrefixLength(const QString &path)
drive++;
if (drive >= size) {
qWarning("Base directory starts with neither a drive nor a UNC share: %s",
- qUtf8Printable(QDir::toNativeSeparators(path)));
+ qUtf8Printable(QDir::toNativeSeparators(path.toString())));
return 0;
}
while (drive < size && path.at(drive).unicode() != '/')
@@ -733,7 +743,7 @@ QString QDir::filePath(const QString &fileName) const
if (treatAsAbsolute(fileName))
return fileName;
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
QString ret = d->dirEntry.filePath();
if (fileName.isEmpty())
return ret;
@@ -741,7 +751,7 @@ QString QDir::filePath(const QString &fileName) const
#ifdef Q_OS_WIN
if (fileName.startsWith(u'/') || fileName.startsWith(u'\\')) {
// Handle the "absolute except for drive" case (i.e. \blah not c:\blah):
- const int drive = drivePrefixLength(ret);
+ const qsizetype drive = drivePrefixLength(ret);
return drive > 0 ? QStringView{ret}.left(drive) % fileName : fileName;
}
#endif // Q_OS_WIN
@@ -764,7 +774,7 @@ QString QDir::absoluteFilePath(const QString &fileName) const
if (treatAsAbsolute(fileName))
return fileName;
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
d->resolveAbsoluteEntry();
const QString absoluteDirPath = d->absoluteDirEntry.filePath();
if (fileName.isEmpty())
@@ -773,7 +783,7 @@ QString QDir::absoluteFilePath(const QString &fileName) const
// Handle the "absolute except for drive" case (i.e. \blah not c:\blah):
if (fileName.startsWith(u'/') || fileName.startsWith(u'\\')) {
// Combine absoluteDirPath's drive with fileName
- const int drive = drivePrefixLength(absoluteDirPath);
+ const qsizetype drive = drivePrefixLength(absoluteDirPath);
if (Q_LIKELY(drive))
return QStringView{absoluteDirPath}.left(drive) % fileName;
@@ -883,7 +893,7 @@ QString QDir::relativeFilePath(const QString &fileName) const
QString QDir::toNativeSeparators(const QString &pathName)
{
#if defined(Q_OS_WIN)
- int i = pathName.indexOf(u'/');
+ qsizetype i = pathName.indexOf(u'/');
if (i != -1) {
QString n(pathName);
@@ -988,6 +998,9 @@ bool QDir::cd(const QString &dirName)
otherwise returns \c false. Note that the logical cdUp() operation is
not performed if the new directory does not exist.
+ \note On Android, this is not supported for content URIs. For more information,
+ see \l {Android: DocumentFile.getParentFile()}{DocumentFile.getParentFile()}.
+
\sa cd(), isReadable(), exists(), path()
*/
bool QDir::cdUp()
@@ -1000,7 +1013,7 @@ bool QDir::cdUp()
*/
QStringList QDir::nameFilters() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return d->nameFilters;
}
@@ -1021,7 +1034,7 @@ QStringList QDir::nameFilters() const
*/
void QDir::setNameFilters(const QStringList &nameFilters)
{
- QDirPrivate* d = d_ptr.data();
+ Q_D(QDir);
d->initFileEngine();
d->clearFileLists();
@@ -1051,12 +1064,12 @@ void QDir::setNameFilters(const QStringList &nameFilters)
*/
void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths)
{
- if (prefix.length() < 2) {
+ if (prefix.size() < 2) {
qWarning("QDir::setSearchPaths: Prefix must be longer than 1 character");
return;
}
- for (int i = 0; i < prefix.length(); ++i) {
+ for (int i = 0; i < prefix.size(); ++i) {
if (!prefix.at(i).isLetterOrNumber()) {
qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
return;
@@ -1108,7 +1121,7 @@ QStringList QDir::searchPaths(const QString &prefix)
*/
QDir::Filters QDir::filter() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return d->filters;
}
@@ -1187,7 +1200,7 @@ QDir::Filters QDir::filter() const
*/
void QDir::setFilter(Filters filters)
{
- QDirPrivate* d = d_ptr.data();
+ Q_D(QDir);
d->initFileEngine();
d->clearFileLists();
@@ -1201,7 +1214,7 @@ void QDir::setFilter(Filters filters)
*/
QDir::SortFlags QDir::sorting() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return d->sort;
}
@@ -1244,7 +1257,7 @@ QDir::SortFlags QDir::sorting() const
*/
void QDir::setSorting(SortFlags sort)
{
- QDirPrivate* d = d_ptr.data();
+ Q_D(QDir);
d->initFileEngine();
d->clearFileLists();
@@ -1260,9 +1273,9 @@ void QDir::setSorting(SortFlags sort)
*/
uint QDir::count() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
d->initFileLists(*this);
- return d->files.count();
+ return d->files.size();
}
/*!
@@ -1274,7 +1287,7 @@ uint QDir::count() const
*/
QString QDir::operator[](int pos) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
d->initFileLists(*this);
return d->files[pos];
}
@@ -1300,7 +1313,7 @@ QString QDir::operator[](int pos) const
*/
QStringList QDir::entryList(Filters filters, SortFlags sort) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return entryList(d->nameFilters, filters, sort);
}
@@ -1323,7 +1336,7 @@ QStringList QDir::entryList(Filters filters, SortFlags sort) const
*/
QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
return entryInfoList(d->nameFilters, filters, sort);
}
@@ -1346,7 +1359,7 @@ QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const
QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
SortFlags sort) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (filters == NoFilter)
filters = d->filters;
@@ -1386,7 +1399,7 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters,
SortFlags sort) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (filters == NoFilter)
filters = d->filters;
@@ -1429,7 +1442,7 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter
*/
bool QDir::mkdir(const QString &dirName, QFile::Permissions permissions) const
{
- const QDirPrivate *d = d_ptr.constData();
+ Q_D(const QDir);
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
@@ -1451,7 +1464,7 @@ bool QDir::mkdir(const QString &dirName, QFile::Permissions permissions) const
*/
bool QDir::mkdir(const QString &dirName) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
@@ -1475,7 +1488,7 @@ bool QDir::mkdir(const QString &dirName) const
*/
bool QDir::rmdir(const QString &dirName) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (dirName.isEmpty()) {
qWarning("QDir::rmdir: Empty or null file name");
@@ -1503,7 +1516,7 @@ bool QDir::rmdir(const QString &dirName) const
*/
bool QDir::mkpath(const QString &dirPath) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (dirPath.isEmpty()) {
qWarning("QDir::mkpath: Empty or null file name");
@@ -1529,7 +1542,7 @@ bool QDir::mkpath(const QString &dirPath) const
*/
bool QDir::rmpath(const QString &dirPath) const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (dirPath.isEmpty()) {
qWarning("QDir::rmpath: Empty or null file name");
@@ -1607,7 +1620,7 @@ bool QDir::removeRecursively()
*/
bool QDir::isReadable() const
{
- const QDirPrivate* d = d_ptr.constData();
+ Q_D(const QDir);
if (!d->fileEngine) {
if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
@@ -1710,7 +1723,7 @@ bool QDir::isRelative() const
*/
bool QDir::makeAbsolute()
{
- const QDirPrivate *d = d_ptr.constData();
+ Q_D(const QDir);
std::unique_ptr<QDirPrivate> dir;
if (!!d->fileEngine) {
QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
@@ -1739,7 +1752,7 @@ bool QDir::makeAbsolute()
*/
bool QDir::operator==(const QDir &dir) const
{
- const QDirPrivate *d = d_ptr.constData();
+ Q_D(const QDir);
const QDirPrivate *other = dir.d_ptr.constData();
if (d == other)
@@ -1889,7 +1902,7 @@ bool QDir::exists(const QString &name) const
*/
bool QDir::isEmpty(Filters filters) const
{
- const auto d = d_ptr.constData();
+ Q_D(const QDir);
QDirIterator it(d->dirEntry.filePath(), d->nameFilters, filters);
return !it.hasNext();
}
@@ -1898,7 +1911,8 @@ bool QDir::isEmpty(Filters filters) const
Returns a list of the root directories on this system.
On Windows this returns a list of QFileInfo objects containing "C:/",
- "D:/", etc. On other operating systems, it returns a list containing
+ "D:/", etc. This does not return drives with ejectable media that are empty.
+ On other operating systems, it returns a list containing
just one root directory (i.e. "/").
\sa root(), rootPath()
@@ -2127,7 +2141,7 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
{
const bool allowUncPaths = flags.testAnyFlag(QDirPrivate::AllowUncPaths);
const bool isRemote = flags.testAnyFlag(QDirPrivate::RemotePath);
- const int len = name.length();
+ const qsizetype len = name.size();
if (ok)
*ok = false;
@@ -2135,15 +2149,15 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
if (len == 0)
return name;
- int i = len - 1;
+ qsizetype i = len - 1;
QVarLengthArray<char16_t> outVector(len);
- int used = len;
+ qsizetype used = len;
char16_t *out = outVector.data();
const ushort *p = reinterpret_cast<const ushort *>(name.data());
const ushort *prefix = p;
- int up = 0;
+ qsizetype up = 0;
- const int prefixLength = rootLength(name, allowUncPaths);
+ const qsizetype prefixLength = rootLength(name, allowUncPaths);
p += prefixLength;
i -= prefixLength;
@@ -2154,10 +2168,10 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
--i;
}
- auto isDot = [](const ushort *p, int i) {
+ auto isDot = [](const ushort *p, qsizetype i) {
return i > 1 && p[i - 1] == '.' && p[i - 2] == '/';
};
- auto isDotDot = [](const ushort *p, int i) {
+ auto isDotDot = [](const ushort *p, qsizetype i) {
return i > 2 && p[i - 1] == '.' && p[i - 2] == '.' && p[i - 3] == '/';
};
@@ -2260,7 +2274,7 @@ QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormaliza
// string only consists of a prefix followed by one or more slashes. Just skip the slash.
++used;
}
- for (int i = prefixLength - 1; i >= 0; --i)
+ for (qsizetype i = prefixLength - 1; i >= 0; --i)
out[--used] = prefix[i];
} else {
if (isEmpty) {
@@ -2292,7 +2306,7 @@ static QString qt_cleanPath(const QString &path, bool *ok)
QString ret = qt_normalizePathSegments(name, OSSupportsUncPaths ? QDirPrivate::AllowUncPaths : QDirPrivate::DefaultNormalization, ok);
// Strip away last slash except for root directories
- if (ret.length() > 1 && ret.endsWith(u'/')) {
+ if (ret.size() > 1 && ret.endsWith(u'/')) {
#if defined (Q_OS_WIN)
if (!(ret.length() == 3 && ret.at(1) == u':'))
#endif
@@ -2338,7 +2352,7 @@ bool QDir::isRelativePath(const QString &path)
*/
void QDir::refresh() const
{
- QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data();
+ QDirPrivate *d = const_cast<QDir *>(this)->d_func();
d->metaData.clear();
d->initFileEngine();
d->clearFileLists();
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index 258bb631da..101c8fd2e7 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -294,7 +294,7 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
return false;
// filter . and ..?
- const int fileNameSize = fileName.size();
+ const qsizetype fileNameSize = fileName.size();
const bool dotOrDotDot = fileName[0] == u'.'
&& ((fileNameSize == 1)
||(fileNameSize == 2 && fileName[1] == u'.'));
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index b1115ad15c..f23b9f77fa 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -192,6 +192,8 @@ QAbstractFileEngine *QFilePrivate::engine() const
function mostly useless for NTFS volumes. It may still be of use for USB
sticks that use VFAT file systems. POSIX ACLs are not manipulated, either.
+ \include android-content-uri-limitations.qdocinc
+
\sa QTextStream, QDataStream, QFileInfo, QDir, {The Qt Resource System}
*/
@@ -725,6 +727,9 @@ QFile::link(const QString &fileName, const QString &linkName)
\include qfile-copy.qdocinc
+ \note On Android, this operation is not yet supported for \c content
+ scheme URIs.
+
\sa setFileName()
*/
@@ -835,6 +840,9 @@ QFile::copy(const QString &newName)
\include qfile-copy.qdocinc
+ \note On Android, this operation is not yet supported for \c content
+ scheme URIs.
+
\sa rename()
*/
@@ -857,6 +865,9 @@ QFile::copy(const QString &fileName, const QString &newName)
will try to create a new file before opening it. The file will be
created with mode 0666 masked by the umask on POSIX systems, and
with permissions inherited from the parent directory on Windows.
+ On Android, it's expected to have access permission to the parent
+ of the file name, otherwise, it won't be possible to create this
+ non-existing file.
\sa QIODevice::OpenMode, setFileName()
*/
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp
index 4e508e6597..90b67a22e3 100644
--- a/src/corelib/io/qfiledevice.cpp
+++ b/src/corelib/io/qfiledevice.cpp
@@ -109,6 +109,11 @@ void QFileDevicePrivate::setError(QFileDevice::FileError err, int errNum)
decrementing \c qt_ntfs_permission_lookup by 1.
\snippet ntfsp.cpp 1
+
+ \note Since this is a non-atomic global variable, it is only safe
+ to increment or decrement \c qt_ntfs_permission_lookup before any
+ threads other than the main thread have started or after every thread
+ other than the main thread has ended.
*/
//************* QFileDevice
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index 963a936d3a..1fbd1e5708 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -265,6 +265,11 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request)
\snippet ntfsp.cpp 1
+ \note Since this is a non-atomic global variable, it is only safe
+ to increment or decrement \c qt_ntfs_permission_lookup before any
+ threads other than the main thread have started or after every thread
+ other than the main thread has ended.
+
\section1 Performance Issues
Some of QFileInfo's functions query the file system, but for
@@ -285,6 +290,10 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request)
If you want to make sure that all information is read from the
file system, use stat().
+ \section1 Platform Specific Issues
+
+ \include android-content-uri-limitations.qdocinc
+
\sa QDir, QFile
*/
@@ -739,7 +748,9 @@ QString QFileInfo::fileName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
- return d->fileEntry.fileName();
+ if (!d->fileEngine)
+ return d->fileEntry.fileName();
+ return d->fileEngine->fileName(QAbstractFileEngine::BaseName);
}
/*!
@@ -783,7 +794,9 @@ QString QFileInfo::baseName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
- return d->fileEntry.baseName();
+ if (!d->fileEngine)
+ return d->fileEntry.baseName();
+ return QFileSystemEntry(d->fileEngine->fileName(QAbstractFileEngine::BaseName)).baseName();
}
/*!
@@ -802,7 +815,10 @@ QString QFileInfo::completeBaseName() const
Q_D(const QFileInfo);
if (d->isDefaultConstructed)
return ""_L1;
- return d->fileEntry.completeBaseName();
+ if (!d->fileEngine)
+ return d->fileEntry.completeBaseName();
+ const QString fileEngineBaseName = d->fileEngine->fileName(QAbstractFileEngine::BaseName);
+ return QFileSystemEntry(fileEngineBaseName).completeBaseName();
}
/*!
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index e622f3af0d..7f5480c274 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -295,7 +295,7 @@ void QFileSelectorPrivate::updateSelectors()
QLatin1Char pathSep(',');
QStringList envSelectors = QString::fromLatin1(qgetenv("QT_FILE_SELECTORS"))
.split(pathSep, Qt::SkipEmptyParts);
- if (envSelectors.count())
+ if (envSelectors.size())
sharedData->staticSelectors << envSelectors;
if (!qEnvironmentVariableIsEmpty(env_override))
diff --git a/src/corelib/io/qfilesystemengine.cpp b/src/corelib/io/qfilesystemengine.cpp
index 3edaf1ce1d..fba1063e9e 100644
--- a/src/corelib/io/qfilesystemengine.cpp
+++ b/src/corelib/io/qfilesystemengine.cpp
@@ -27,7 +27,7 @@ QString QFileSystemEngine::slowCanonicalized(const QString &path)
QFileInfo fi;
const QChar slash(u'/');
QString tmpPath = path;
- int separatorPos = 0;
+ qsizetype separatorPos = 0;
QSet<QString> nonSymlinks;
QDuplicateTracker<QString> known;
@@ -104,7 +104,7 @@ static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &ent
return _q_checkEntry(engine, resolvingEntry);
#if defined(QT_BUILD_CORE_LIB)
- for (int prefixSeparator = 0; prefixSeparator < filePath.size(); ++prefixSeparator) {
+ for (qsizetype prefixSeparator = 0; prefixSeparator < filePath.size(); ++prefixSeparator) {
QChar const ch = filePath[prefixSeparator];
if (ch == u'/')
break;
@@ -119,7 +119,7 @@ static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &ent
break;
const QStringList &paths = QDir::searchPaths(filePath.left(prefixSeparator));
- for (int i = 0; i < paths.count(); i++) {
+ for (qsizetype i = 0; i < paths.size(); i++) {
entry = QFileSystemEntry(QDir::cleanPath(
paths.at(i) % u'/' % QStringView{filePath}.mid(prefixSeparator + 1)));
// Recurse!
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 9036608e7d..0645952091 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -591,7 +591,7 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link,
Q_CHECK_FILE_NAME(link, link);
QByteArray s = qt_readlink(link.nativeFilePath().constData());
- if (s.length() > 0) {
+ if (s.size() > 0) {
QString ret;
if (!data.hasFlags(QFileSystemMetaData::DirectoryType))
fillMetaData(link, data, QFileSystemMetaData::DirectoryType);
@@ -713,13 +713,13 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
QFileSystemEntry cur(currentPath());
result = cur.nativeFilePath();
}
- if (!orig.isEmpty() && !(orig.length() == 1 && orig[0] == '.')) {
+ if (!orig.isEmpty() && !(orig.size() == 1 && orig[0] == '.')) {
if (!result.isEmpty() && !result.endsWith('/'))
result.append('/');
result.append(orig);
}
- if (result.length() == 1 && result[0] == '/')
+ if (result.size() == 1 && result[0] == '/')
return QFileSystemEntry(result, QFileSystemEntry::FromNativePath());
const bool isDir = result.endsWith('/');
@@ -1152,7 +1152,7 @@ bool QFileSystemEngine::removeDirectory(const QFileSystemEntry &entry, bool remo
if (removeEmptyParents) {
QString dirName = QDir::cleanPath(entry.filePath());
- for (int oldslash = 0, slash=dirName.length(); slash > 0; oldslash = slash) {
+ for (int oldslash = 0, slash=dirName.size(); slash > 0; oldslash = slash) {
const QByteArray chunk = QFile::encodeName(dirName.left(slash));
QT_STATBUF st;
if (QT_STAT(chunk.constData(), &st) != -1) {
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp
index eef21b2fd4..3b53b490f5 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify.cpp
+++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp
@@ -223,7 +223,7 @@ QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd, QObject
QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine()
{
notifier.setEnabled(false);
- for (int id : qAsConst(pathToID))
+ for (int id : std::as_const(pathToID))
inotify_rm_watch(inotifyFd, id < 0 ? -id : id);
::close(inotifyFd);
diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
index 2cd650a296..40d4c1f150 100644
--- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp
+++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp
@@ -51,7 +51,7 @@ QKqueueFileSystemWatcherEngine::~QKqueueFileSystemWatcherEngine()
notifier.setEnabled(false);
close(kqfd);
- for (int id : qAsConst(pathToID))
+ for (int id : std::as_const(pathToID))
::close(id < 0 ? -id : id);
}
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp
index 4c53e4faac..a0b2b006d6 100644
--- a/src/corelib/io/qfilesystemwatcher_win.cpp
+++ b/src/corelib/io/qfilesystemwatcher_win.cpp
@@ -317,9 +317,9 @@ QWindowsFileSystemWatcherEngine::QWindowsFileSystemWatcherEngine(QObject *parent
QWindowsFileSystemWatcherEngine::~QWindowsFileSystemWatcherEngine()
{
- for (auto *thread : qAsConst(threads))
+ for (auto *thread : std::as_const(threads))
thread->stop();
- for (auto *thread : qAsConst(threads))
+ for (auto *thread : std::as_const(threads))
thread->wait();
qDeleteAll(threads);
}
@@ -332,12 +332,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
QStringList unhandled;
for (const QString &path : paths) {
auto sg = qScopeGuard([&] { unhandled.push_back(path); });
- QString normalPath = path;
- if ((normalPath.endsWith(u'/') && !normalPath.endsWith(":/"_L1))
- || (normalPath.endsWith(u'\\') && !normalPath.endsWith(":\\"_L1))) {
- normalPath.chop(1);
- }
- QFileInfo fileInfo(normalPath);
+ QFileInfo fileInfo(path);
fileInfo.stat();
if (!fileInfo.exists())
continue;
@@ -351,7 +346,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
continue;
}
- DEBUG() << "Looking for a thread/handle for" << normalPath;
+ DEBUG() << "Looking for a thread/handle for" << fileInfo.path();
const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath();
const uint flags = isDir
@@ -433,7 +428,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
// now look for a thread to insert
bool found = false;
- for (QWindowsFileSystemWatcherEngineThread *thread : qAsConst(threads)) {
+ for (QWindowsFileSystemWatcherEngineThread *thread : std::as_const(threads)) {
const auto locker = qt_scoped_lock(thread->mutex);
if (thread->handles.count() < MAXIMUM_WAIT_OBJECTS) {
DEBUG() << "Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath()
@@ -495,11 +490,8 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path
QStringList unhandled;
for (const QString &path : paths) {
auto sg = qScopeGuard([&] { unhandled.push_back(path); });
- QString normalPath = path;
- if (normalPath.endsWith(u'/') || normalPath.endsWith(u'\\'))
- normalPath.chop(1);
- QFileInfo fileInfo(normalPath);
- DEBUG() << "removing" << normalPath;
+ QFileInfo fileInfo(path);
+ DEBUG() << "removing" << fileInfo.path();
QString absolutePath = fileInfo.absoluteFilePath();
QList<QWindowsFileSystemWatcherEngineThread *>::iterator jt, end;
end = threads.end();
@@ -586,7 +578,7 @@ QWindowsFileSystemWatcherEngineThread::~QWindowsFileSystemWatcherEngineThread()
CloseHandle(handles.at(0));
handles[0] = INVALID_HANDLE_VALUE;
- for (HANDLE h : qAsConst(handles)) {
+ for (HANDLE h : std::as_const(handles)) {
if (h == INVALID_HANDLE_VALUE)
continue;
FindCloseChangeNotification(h);
diff --git a/src/corelib/io/qfilesystemwatcher_win_p.h b/src/corelib/io/qfilesystemwatcher_win_p.h
index 3678043351..79cec00c39 100644
--- a/src/corelib/io/qfilesystemwatcher_win_p.h
+++ b/src/corelib/io/qfilesystemwatcher_win_p.h
@@ -104,7 +104,10 @@ public:
Q_DECLARE_TYPEINFO(QFileSystemWatcherPathKey, Q_RELOCATABLE_TYPE);
-inline size_t qHash(const QFileSystemWatcherPathKey &key) { return qHash(key.toCaseFolded()); }
+inline size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed = 0)
+{
+ return qHash(key.toCaseFolded(), seed);
+}
class QWindowsFileSystemWatcherEngineThread : public QThread
{
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index 23698930c0..ffc4878e0d 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -328,7 +328,7 @@ bool QFSFileEnginePrivate::openFd(QIODevice::OpenMode openMode, int fd)
// Seek to the end when in Append mode.
if (openMode & QFile::Append) {
- int ret;
+ QT_OFF_T ret;
do {
ret = QT_LSEEK(fd, 0, SEEK_END);
} while (ret == -1 && errno == EINTR);
@@ -468,7 +468,7 @@ void QFSFileEnginePrivate::unmapAll()
{
if (!maps.isEmpty()) {
const QList<uchar*> keys = maps.keys(); // Make a copy since unmap() modifies the map.
- for (int i = 0; i < keys.count(); ++i)
+ for (int i = 0; i < keys.size(); ++i)
unmap(keys.at(i));
}
}
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index a127b76fcc..fb08385c91 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -115,14 +115,14 @@ bool QFSFileEnginePrivate::nativeOpenImpl(QIODevice::OpenMode openMode, mode_t m
// Seek to the end when in Append mode.
if (flags & QFile::Append) {
- int ret;
+ QT_OFF_T ret;
do {
ret = QT_LSEEK(fd, 0, SEEK_END);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
- qt_error_string(int(errno)));
+ qt_error_string(errno));
return false;
}
}
@@ -221,7 +221,7 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len)
}
if (readBytes == 0 && !feof(fh)) {
// if we didn't read anything and we're not at EOF, it must be an error
- q->setError(QFile::ReadError, qt_error_string(int(errno)));
+ q->setError(QFile::ReadError, qt_error_string(errno));
return -1;
}
return readBytes;
@@ -489,6 +489,10 @@ bool QFSFileEngine::setPermissions(uint perms)
Q_D(QFSFileEngine);
QSystemError error;
bool ok;
+
+ // clear cached state (if any)
+ d->metaData.clearFlags(QFileSystemMetaData::Permissions);
+
if (d->fd != -1)
ok = QFileSystemEngine::setPermissions(d->fd, QFile::Permissions(perms), error);
else
@@ -550,13 +554,13 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
Q_Q(QFSFileEngine);
if (openMode == QIODevice::NotOpen) {
- q->setError(QFile::PermissionsError, qt_error_string(int(EACCES)));
+ q->setError(QFile::PermissionsError, qt_error_string(EACCES));
return nullptr;
}
if (offset < 0 || offset > maxFileOffset
|| size < 0 || quint64(size) > quint64(size_t(-1))) {
- q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL)));
+ q->setError(QFile::UnspecifiedError, qt_error_string(EINVAL));
return nullptr;
}
@@ -584,7 +588,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
int extra = offset % pageSize;
if (quint64(size + extra) > quint64((size_t)-1)) {
- q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL)));
+ q->setError(QFile::UnspecifiedError, qt_error_string(EINVAL));
return nullptr;
}
@@ -602,16 +606,16 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
switch(errno) {
case EBADF:
- q->setError(QFile::PermissionsError, qt_error_string(int(EACCES)));
+ q->setError(QFile::PermissionsError, qt_error_string(EACCES));
break;
case ENFILE:
case ENOMEM:
- q->setError(QFile::ResourceError, qt_error_string(int(errno)));
+ q->setError(QFile::ResourceError, qt_error_string(errno));
break;
case EINVAL:
// size are out of bounds
default:
- q->setError(QFile::UnspecifiedError, qt_error_string(int(errno)));
+ q->setError(QFile::UnspecifiedError, qt_error_string(errno));
break;
}
return nullptr;
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index ae59cf9e55..1030c55937 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -655,6 +655,10 @@ bool QFSFileEngine::setPermissions(uint perms)
{
Q_D(QFSFileEngine);
QSystemError error;
+
+ // clear cached state (if any)
+ d->metaData.clearFlags(QFileSystemMetaData::Permissions);
+
bool ret = QFileSystemEngine::setPermissions(d->fileEntry, QFile::Permissions(perms), error);
if (!ret)
setError(QFile::PermissionsError, error.toString());
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index eeb3d79b06..feed38bef6 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -60,11 +60,9 @@ static bool parseIp4Internal(IPv4Address &address, const char *ptr, bool acceptL
ptr[1] != '.' && ptr[1] != '\0')
return false;
- const char *endptr;
- bool ok;
- quint64 ll = qstrntoull(ptr, stop - ptr, &endptr, 0, &ok);
+ auto [ll, endptr] = qstrntoull(ptr, stop - ptr, 0);
quint32 x = ll;
- if (!ok || endptr == ptr || ll != x)
+ if (!endptr || endptr == ptr || ll != x)
return false;
if (*endptr == '.' || dotCount == 3) {
@@ -176,15 +174,13 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end
continue;
}
- const char *endptr;
- bool ok;
- quint64 ll = qstrntoull(ptr, stop - ptr, &endptr, 16, &ok);
+ auto [ll, endptr] = qstrntoull(ptr, stop - ptr, 16);
quint16 x = ll;
// Reject malformed fields:
// - failed to parse
// - too many hex digits
- if (!ok || endptr > ptr + 4)
+ if (!endptr || endptr > ptr + 4)
return begin + (ptr - buffer.data());
if (*endptr == '.') {
diff --git a/src/corelib/io/qlockfile.h b/src/corelib/io/qlockfile.h
index bc704ea28f..b63194dcd3 100644
--- a/src/corelib/io/qlockfile.h
+++ b/src/corelib/io/qlockfile.h
@@ -7,9 +7,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
-#if __has_include(<chrono>)
-# include <chrono>
-#endif
+#include <chrono>
QT_BEGIN_NAMESPACE
@@ -30,7 +28,6 @@ public:
void setStaleLockTime(int);
int staleLockTime() const;
-#if __has_include(<chrono>)
bool tryLock(std::chrono::milliseconds timeout) { return tryLock(int(timeout.count())); }
void setStaleLockTime(std::chrono::milliseconds value) { setStaleLockTime(int(value.count())); }
@@ -39,7 +36,6 @@ public:
{
return std::chrono::milliseconds(staleLockTime());
}
-#endif
bool isLocked() const;
bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 8136b5f545..425eb40eb3 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -595,8 +595,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
with a specific name. The implicitly-defined QLoggingCategory object is
created on first use, in a thread-safe manner.
- This macro must be used outside of a class or method. It is only defined
- if variadic macros are supported.
+ This macro must be used outside of a class or method.
*/
QT_END_NAMESPACE
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index 7eac497cea..3fd5a55637 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -167,7 +167,6 @@ struct QResourceGlobalData
{
QRecursiveMutex resourceMutex;
ResourceList resourceList;
- QStringList resourceSearchPaths;
};
Q_GLOBAL_STATIC(QResourceGlobalData, resourceGlobalData)
@@ -177,9 +176,6 @@ static inline QRecursiveMutex &resourceMutex()
static inline ResourceList *resourceList()
{ return &resourceGlobalData->resourceList; }
-static inline QStringList *resourceSearchPaths()
-{ return &resourceGlobalData->resourceSearchPaths; }
-
/*!
\class QResource
\inmodule QtCore
@@ -360,16 +356,10 @@ void QResourcePrivate::ensureInitialized() const
if (path.startsWith(u'/')) {
that->load(path.toString());
} else {
- const auto locker = qt_scoped_lock(resourceMutex());
- QStringList searchPaths = *resourceSearchPaths();
- searchPaths << ""_L1;
- for (int i = 0; i < searchPaths.size(); ++i) {
- const QString searchPath(searchPaths.at(i) + u'/' + path);
- if (that->load(searchPath)) {
- that->absoluteFilePath = u':' + searchPath;
- break;
- }
- }
+ // Should we search QDir::searchPath() before falling back to root ?
+ const QString searchPath(u'/' + path);
+ if (that->load(searchPath))
+ that->absoluteFilePath = u':' + searchPath;
}
}
@@ -779,7 +769,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
if (!root.endsWith(u'/'))
root += u'/';
if (path.size() >= root.size() && path.startsWith(root))
- path = path.mid(root.length() - 1);
+ path = path.mid(root.size() - 1);
if (path.isEmpty())
path = u'/';
}
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index 60622e3aaa..d7185e0c01 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -343,7 +343,7 @@ void QSettingsPrivate::requestUpdate()
QStringList QSettingsPrivate::variantListToStringList(const QVariantList &l)
{
QStringList result;
- result.reserve(l.count());
+ result.reserve(l.size());
for (auto v : l)
result.append(variantToString(v));
return result;
@@ -356,9 +356,9 @@ QVariant QSettingsPrivate::stringListToVariantList(const QStringList &l)
const QString &str = outStringList.at(i);
if (str.startsWith(u'@')) {
- if (str.length() < 2 || str.at(1) != u'@') {
+ if (str.size() < 2 || str.at(1) != u'@') {
QVariantList variantList;
- variantList.reserve(l.count());
+ variantList.reserve(l.size());
for (const auto &s : l)
variantList.append(stringToVariant(s));
return variantList;
@@ -511,7 +511,7 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s)
void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result)
{
- result.reserve(result.length() + key.length() * 3 / 2);
+ result.reserve(result.size() + key.size() * 3 / 2);
for (qsizetype i = 0; i < key.size(); ++i) {
uint ch = key.at(i).unicode();
@@ -540,7 +540,7 @@ bool QSettingsPrivate::iniUnescapedKey(QByteArrayView key, QString &result)
{
const QString decoded = QString::fromUtf8(key);
const qsizetype size = decoded.size();
- result.reserve(result.length() + size);
+ result.reserve(result.size() + size);
qsizetype i = 0;
bool lowercaseOnly = true;
while (i < size) {
@@ -735,7 +735,7 @@ StSkipSpaces:
// fallthrough
StNormal:
- qsizetype chopLimit = stringResult.length();
+ qsizetype chopLimit = stringResult.size();
while (i < str.size()) {
switch (str.at(i)) {
case '\\':
@@ -773,7 +773,7 @@ StNormal:
} else {
// the character is skipped
}
- chopLimit = stringResult.length();
+ chopLimit = stringResult.size();
break;
case '"':
++i;
@@ -860,7 +860,7 @@ end:
QStringList QSettingsPrivate::splitArgs(const QString &s, qsizetype idx)
{
- qsizetype l = s.length();
+ qsizetype l = s.size();
Q_ASSERT(l > 0);
Q_ASSERT(s.at(idx) == u'(');
Q_ASSERT(s.at(l - 1) == u')');
@@ -1085,16 +1085,16 @@ QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format,
QStringList paths;
if (!application.isEmpty()) {
paths.reserve(dirs.size() * 2);
- for (const auto &dir : qAsConst(dirs))
+ for (const auto &dir : std::as_const(dirs))
paths.append(dir + u'/' + appFile);
} else {
paths.reserve(dirs.size());
}
- for (const auto &dir : qAsConst(dirs))
+ for (const auto &dir : std::as_const(dirs))
paths.append(dir + u'/' + orgFile);
// Note: No check for existence of files is done intentionally.
- for (const auto &path : qAsConst(paths))
+ for (const auto &path : std::as_const(paths))
confFiles.append(QConfFile::fromName(path, false));
} else
#endif // Q_XDG_PLATFORM && !QT_NO_STANDARDPATHS
@@ -1127,7 +1127,7 @@ QConfFileSettingsPrivate::~QConfFileSettingsPrivate()
ConfFileHash *usedHash = usedHashFunc();
ConfFileCache *unusedCache = unusedCacheFunc();
- for (auto conf_file : qAsConst(confFiles)) {
+ for (auto conf_file : std::as_const(confFiles)) {
if (!conf_file->ref.deref()) {
if (conf_file->size == 0) {
delete conf_file;
@@ -1201,7 +1201,7 @@ std::optional<QVariant> QConfFileSettingsPrivate::get(const QString &key) const
ParsedSettingsMap::const_iterator j;
bool found = false;
- for (auto confFile : qAsConst(confFiles)) {
+ for (auto confFile : std::as_const(confFiles)) {
const auto locker = qt_scoped_lock(confFile->mutex);
if (!confFile->addedKeys.isEmpty()) {
@@ -1230,7 +1230,7 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec
QSettingsKey thePrefix(prefix, caseSensitivity);
qsizetype startPos = prefix.size();
- for (auto confFile : qAsConst(confFiles)) {
+ for (auto confFile : std::as_const(confFiles)) {
const auto locker = qt_scoped_lock(confFile->mutex);
if (thePrefix.isEmpty())
@@ -1281,7 +1281,7 @@ void QConfFileSettingsPrivate::sync()
// people probably won't be checking the status a whole lot, so in case of
// error we just try to go on and make the best of it
- for (auto confFile : qAsConst(confFiles)) {
+ for (auto confFile : std::as_const(confFiles)) {
const auto locker = qt_scoped_lock(confFile->mutex);
syncConfFile(confFile);
}
@@ -1515,7 +1515,7 @@ bool QConfFileSettingsPrivate::readIniLine(QByteArrayView data, qsizetype &dataP
qsizetype &lineStart, qsizetype &lineLen,
qsizetype &equalsPos)
{
- qsizetype dataLen = data.length();
+ qsizetype dataLen = data.size();
bool inQuotes = false;
equalsPos = -1;
@@ -1643,7 +1643,7 @@ bool QConfFileSettingsPrivate::readIniFile(QByteArrayView data,
++position;
}
- Q_ASSERT(lineStart == data.length());
+ Q_ASSERT(lineStart == data.size());
FLUSH_CURRENT_SECTION();
return ok;
diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h
index b8fba349ca..5d2c330728 100644
--- a/src/corelib/io/qsettings.h
+++ b/src/corelib/io/qsettings.h
@@ -54,6 +54,12 @@ public:
Registry64Format,
#endif
+#if defined(Q_OS_WASM)
+ // FIXME: add public API in next minor release.
+ // WebLocalStorageFormat (IniFormat + 1)
+ // WebIDBSFormat (IniFormat + 2)
+#endif
+
InvalidFormat = 16,
CustomFormat1,
CustomFormat2,
diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h
index d1ea37ea0c..2429820242 100644
--- a/src/corelib/io/qsettings_p.h
+++ b/src/corelib/io/qsettings_p.h
@@ -216,10 +216,6 @@ protected:
mutable QSettings::Status status;
};
-#ifdef Q_OS_WASM
-class QWasmSettingsPrivate;
-#endif
-
class QConfFileSettingsPrivate : public QSettingsPrivate
{
public:
@@ -266,7 +262,7 @@ private:
Qt::CaseSensitivity caseSensitivity;
qsizetype nextPosition;
#ifdef Q_OS_WASM
- friend class QWasmSettingsPrivate;
+ friend class QWasmIDBSettingsPrivate;
#endif
};
diff --git a/src/corelib/io/qsettings_wasm.cpp b/src/corelib/io/qsettings_wasm.cpp
index 5c15e6d89b..15ab688abe 100644
--- a/src/corelib/io/qsettings_wasm.cpp
+++ b/src/corelib/io/qsettings_wasm.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 The Qt Company Ltd.
+// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsettings.h"
@@ -16,20 +16,168 @@
#include <QList>
#include <emscripten.h>
+#include <emscripten/val.h>
QT_BEGIN_NAMESPACE
+using emscripten::val;
using namespace Qt::StringLiterals;
-static bool isReadReady = false;
+//
+// Native settings implementation for WebAssembly using window.localStorage
+// as the storage backend. localStorage is a key-value store with a synchronous
+// API and a 5MB storage limit.
+//
+class QWasmLocalStorageSettingsPrivate final : public QSettingsPrivate
+{
+public:
+ QWasmLocalStorageSettingsPrivate(QSettings::Scope scope, const QString &organization,
+ const QString &application);
+
+ void remove(const QString &key) final;
+ void set(const QString &key, const QVariant &value) final;
+ std::optional<QVariant> get(const QString &key) const final;
+ QStringList children(const QString &prefix, ChildSpec spec) const final;
+ void clear() final;
+ void sync() final;
+ void flush() final;
+ bool isWritable() const final;
+ QString fileName() const final;
+
+private:
+ QString prependStoragePrefix(const QString &key) const;
+ QStringView removeStoragePrefix(QStringView key) const;
+ val m_localStorage = val::global("window")["localStorage"];
+ QString m_keyPrefix;
+};
+
+QWasmLocalStorageSettingsPrivate::QWasmLocalStorageSettingsPrivate(QSettings::Scope scope,
+ const QString &organization,
+ const QString &application)
+ : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application)
+{
+ // The key prefix contians "qt" to separate Qt keys from other keys on localStorage, a
+ // version tag to allow for making changes to the key format in the future, the org
+ // and app names.
+ //
+ // User code could could create separate settings object with different org and app names,
+ // and would expect them to have separate settings. Also, different webassembly instanaces
+ // on the page could write to the same window.localStorage. Add the org and app name
+ // to the key prefix to differentiate, even if that leads to keys with redundant sectons
+ // for the common case of a single org and app name.
+ const QLatin1String separator("-");
+ const QLatin1String doubleSeparator("--");
+ const QString escapedOrganization = QString(organization).replace(separator, doubleSeparator);
+ const QString escapedApplication = QString(application).replace(separator, doubleSeparator);
+ const QLatin1String prefix("qt-v0-");
+ m_keyPrefix.reserve(prefix.length() + escapedOrganization.length() +
+ escapedApplication.length() + separator.length() * 2);
+ m_keyPrefix = prefix + escapedOrganization + separator + escapedApplication + separator;
+}
+
+void QWasmLocalStorageSettingsPrivate::remove(const QString &key)
+{
+ const std::string keyString = prependStoragePrefix(key).toStdString();
+ m_localStorage.call<val>("removeItem", keyString);
+}
+
+void QWasmLocalStorageSettingsPrivate::set(const QString &key, const QVariant &value)
+{
+ const std::string keyString = prependStoragePrefix(key).toStdString();
+ const std::string valueString = QSettingsPrivate::variantToString(value).toStdString();
+ m_localStorage.call<void>("setItem", keyString, valueString);
+}
-class QWasmSettingsPrivate : public QConfFileSettingsPrivate
+std::optional<QVariant> QWasmLocalStorageSettingsPrivate::get(const QString &key) const
+{
+ const std::string keyString = prependStoragePrefix(key).toStdString();
+ const emscripten::val value = m_localStorage.call<val>("getItem", keyString);
+ if (value.isNull())
+ return std::nullopt;
+ const QString valueString = QString::fromStdString(value.as<std::string>());
+ return QSettingsPrivate::stringToVariant(valueString);
+}
+
+QStringList QWasmLocalStorageSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
+{
+ // Loop through all keys on window.localStorage, return Qt keys belonging to
+ // this application, with the correct prefix, and according to ChildSpec.
+ QStringList children;
+ const int length = m_localStorage["length"].as<int>();
+ for (int i = 0; i < length; ++i) {
+ const QString keyString =
+ QString::fromStdString(m_localStorage.call<val>("key", i).as<std::string>());
+
+ const QStringView key = removeStoragePrefix(QStringView(keyString));
+ if (key.isEmpty())
+ continue;
+ if (!key.startsWith(prefix))
+ continue;
+
+ QSettingsPrivate::processChild(key.sliced(prefix.length()), spec, children);
+ }
+
+ return children;
+}
+
+void QWasmLocalStorageSettingsPrivate::clear()
+{
+ // Get all Qt keys from window.localStorage
+ const int length = m_localStorage["length"].as<int>();
+ std::vector<std::string> keys;
+ keys.reserve(length);
+ for (int i = 0; i < length; ++i) {
+ std::string key = (m_localStorage.call<val>("key", i).as<std::string>());
+ keys.push_back(std::move(key));
+ }
+
+ // Remove all Qt keys. Note that localStorage does not guarantee a stable
+ // iteration order when the storage is mutated, which is why removal is done
+ // in a second step after getting all keys.
+ for (std::string key: keys) {
+ if (removeStoragePrefix(QString::fromStdString(key)).isEmpty() == false)
+ m_localStorage.call<val>("removeItem", key);
+ }
+}
+
+void QWasmLocalStorageSettingsPrivate::sync() { }
+
+void QWasmLocalStorageSettingsPrivate::flush() { }
+
+bool QWasmLocalStorageSettingsPrivate::isWritable() const
+{
+ return true;
+}
+
+QString QWasmLocalStorageSettingsPrivate::fileName() const
+{
+ return QString();
+}
+
+QString QWasmLocalStorageSettingsPrivate::prependStoragePrefix(const QString &key) const
+{
+ return m_keyPrefix + key;
+}
+
+QStringView QWasmLocalStorageSettingsPrivate::removeStoragePrefix(QStringView key) const
+{
+ // Return the key slice after m_keyPrefix, or an empty string view if no match
+ if (!key.startsWith(m_keyPrefix))
+ return QStringView();
+ return key.sliced(m_keyPrefix.length());
+}
+
+//
+// Native settings implementation for WebAssembly using the indexed database as
+// the storage backend
+//
+class QWasmIDBSettingsPrivate : public QConfFileSettingsPrivate
{
public:
- QWasmSettingsPrivate(QSettings::Scope scope, const QString &organization,
- const QString &application);
- ~QWasmSettingsPrivate();
- static QWasmSettingsPrivate *get(void *userData);
+ QWasmIDBSettingsPrivate(QSettings::Scope scope, const QString &organization,
+ const QString &application);
+ ~QWasmIDBSettingsPrivate();
+ static QWasmIDBSettingsPrivate *get(void *userData);
std::optional<QVariant> get(const QString &key) const override;
QStringList children(const QString &prefix, ChildSpec spec) const override;
@@ -46,14 +194,15 @@ public:
private:
QString databaseName;
QString id;
- static QList<QWasmSettingsPrivate *> liveSettings;
+ static QList<QWasmIDBSettingsPrivate *> liveSettings;
};
-QList<QWasmSettingsPrivate *> QWasmSettingsPrivate::liveSettings;
+QList<QWasmIDBSettingsPrivate *> QWasmIDBSettingsPrivate::liveSettings;
+static bool isReadReady = false;
-static void QWasmSettingsPrivate_onLoad(void *userData, void *dataPtr, int size)
+static void QWasmIDBSettingsPrivate_onLoad(void *userData, void *dataPtr, int size)
{
- QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData);
+ QWasmIDBSettingsPrivate *settings = QWasmIDBSettingsPrivate::get(userData);
if (!settings)
return;
@@ -70,21 +219,21 @@ static void QWasmSettingsPrivate_onLoad(void *userData, void *dataPtr, int size)
}
}
-static void QWasmSettingsPrivate_onError(void *userData)
+static void QWasmIDBSettingsPrivate_onError(void *userData)
{
- if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData))
+ if (QWasmIDBSettingsPrivate *settings = QWasmIDBSettingsPrivate::get(userData))
settings->setStatus(QSettings::AccessError);
}
-static void QWasmSettingsPrivate_onStore(void *userData)
+static void QWasmIDBSettingsPrivate_onStore(void *userData)
{
- if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData))
+ if (QWasmIDBSettingsPrivate *settings = QWasmIDBSettingsPrivate::get(userData))
settings->setStatus(QSettings::NoError);
}
-static void QWasmSettingsPrivate_onCheck(void *userData, int exists)
+static void QWasmIDBSettingsPrivate_onCheck(void *userData, int exists)
{
- if (QWasmSettingsPrivate *settings = QWasmSettingsPrivate::get(userData)) {
+ if (QWasmIDBSettingsPrivate *settings = QWasmIDBSettingsPrivate::get(userData)) {
if (exists)
settings->loadLocal(settings->fileName().toLocal8Bit());
else
@@ -92,31 +241,9 @@ static void QWasmSettingsPrivate_onCheck(void *userData, int exists)
}
}
-QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format,
- QSettings::Scope scope,
- const QString &organization,
- const QString &application)
-{
- Q_UNUSED(format);
- if (organization == "Qt"_L1)
- {
- QString organizationDomain = QCoreApplication::organizationDomain();
- QString applicationName = QCoreApplication::applicationName();
-
- QSettingsPrivate *newSettings;
- newSettings = new QWasmSettingsPrivate(scope, organizationDomain, applicationName);
-
- newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(organization)));
- if (!application.isEmpty())
- newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(application)));
-
- return newSettings;
- }
- return new QWasmSettingsPrivate(scope, organization, application);
-}
-
-QWasmSettingsPrivate::QWasmSettingsPrivate(QSettings::Scope scope, const QString &organization,
- const QString &application)
+QWasmIDBSettingsPrivate::QWasmIDBSettingsPrivate(QSettings::Scope scope,
+ const QString &organization,
+ const QString &application)
: QConfFileSettingsPrivate(QSettings::NativeFormat, scope, organization, application)
{
liveSettings.push_back(this);
@@ -128,29 +255,29 @@ QWasmSettingsPrivate::QWasmSettingsPrivate(QSettings::Scope scope, const QString
emscripten_idb_async_exists("/home/web_user",
fileName().toLocal8Bit(),
reinterpret_cast<void*>(this),
- QWasmSettingsPrivate_onCheck,
- QWasmSettingsPrivate_onError);
+ QWasmIDBSettingsPrivate_onCheck,
+ QWasmIDBSettingsPrivate_onError);
}
-QWasmSettingsPrivate::~QWasmSettingsPrivate()
+QWasmIDBSettingsPrivate::~QWasmIDBSettingsPrivate()
{
liveSettings.removeAll(this);
}
-QWasmSettingsPrivate *QWasmSettingsPrivate::get(void *userData)
+QWasmIDBSettingsPrivate *QWasmIDBSettingsPrivate::get(void *userData)
{
- if (QWasmSettingsPrivate::liveSettings.contains(userData))
- return reinterpret_cast<QWasmSettingsPrivate *>(userData);
+ if (QWasmIDBSettingsPrivate::liveSettings.contains(userData))
+ return reinterpret_cast<QWasmIDBSettingsPrivate *>(userData);
return nullptr;
}
- void QWasmSettingsPrivate::initAccess()
+void QWasmIDBSettingsPrivate::initAccess()
{
if (isReadReady)
QConfFileSettingsPrivate::initAccess();
}
-std::optional<QVariant> QWasmSettingsPrivate::get(const QString &key) const
+std::optional<QVariant> QWasmIDBSettingsPrivate::get(const QString &key) const
{
if (isReadReady)
return QConfFileSettingsPrivate::get(key);
@@ -158,22 +285,22 @@ std::optional<QVariant> QWasmSettingsPrivate::get(const QString &key) const
return std::nullopt;
}
-QStringList QWasmSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
+QStringList QWasmIDBSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
{
return QConfFileSettingsPrivate::children(prefix, spec);
}
-void QWasmSettingsPrivate::clear()
+void QWasmIDBSettingsPrivate::clear()
{
QConfFileSettingsPrivate::clear();
emscripten_idb_async_delete("/home/web_user",
fileName().toLocal8Bit(),
reinterpret_cast<void*>(this),
- QWasmSettingsPrivate_onStore,
- QWasmSettingsPrivate_onError);
+ QWasmIDBSettingsPrivate_onStore,
+ QWasmIDBSettingsPrivate_onError);
}
-void QWasmSettingsPrivate::sync()
+void QWasmIDBSettingsPrivate::sync()
{
QConfFileSettingsPrivate::sync();
@@ -186,22 +313,22 @@ void QWasmSettingsPrivate::sync()
reinterpret_cast<void *>(dataPointer.data()),
dataPointer.length(),
reinterpret_cast<void*>(this),
- QWasmSettingsPrivate_onStore,
- QWasmSettingsPrivate_onError);
+ QWasmIDBSettingsPrivate_onStore,
+ QWasmIDBSettingsPrivate_onError);
}
}
-void QWasmSettingsPrivate::flush()
+void QWasmIDBSettingsPrivate::flush()
{
sync();
}
-bool QWasmSettingsPrivate::isWritable() const
+bool QWasmIDBSettingsPrivate::isWritable() const
{
return isReadReady && QConfFileSettingsPrivate::isWritable();
}
-void QWasmSettingsPrivate::syncToLocal(const char *data, int size)
+void QWasmIDBSettingsPrivate::syncToLocal(const char *data, int size)
{
QFile file(fileName());
@@ -214,27 +341,62 @@ void QWasmSettingsPrivate::syncToLocal(const char *data, int size)
reinterpret_cast<void *>(data.data()),
data.length(),
reinterpret_cast<void*>(this),
- QWasmSettingsPrivate_onStore,
- QWasmSettingsPrivate_onError);
+ QWasmIDBSettingsPrivate_onStore,
+ QWasmIDBSettingsPrivate_onError);
setReady();
}
}
-void QWasmSettingsPrivate::loadLocal(const QByteArray &filename)
+void QWasmIDBSettingsPrivate::loadLocal(const QByteArray &filename)
{
emscripten_idb_async_load("/home/web_user",
filename.data(),
reinterpret_cast<void*>(this),
- QWasmSettingsPrivate_onLoad,
- QWasmSettingsPrivate_onError);
+ QWasmIDBSettingsPrivate_onLoad,
+ QWasmIDBSettingsPrivate_onError);
}
-void QWasmSettingsPrivate::setReady()
+void QWasmIDBSettingsPrivate::setReady()
{
isReadReady = true;
setStatus(QSettings::NoError);
QConfFileSettingsPrivate::initAccess();
}
+QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope,
+ const QString &organization, const QString &application)
+{
+ const auto WebLocalStorageFormat = QSettings::IniFormat + 1;
+ const auto WebIdbFormat = QSettings::IniFormat + 2;
+
+ // Make WebLocalStorageFormat the default native format
+ if (format == QSettings::NativeFormat)
+ format = QSettings::Format(WebLocalStorageFormat);
+
+ // Check if cookies are enabled (required for using persistent storage)
+ const bool cookiesEnabled = val::global("navigator")["cookieEnabled"].as<bool>();
+ constexpr QLatin1StringView cookiesWarningMessage
+ ("QSettings::%1 requires cookies, falling back to IniFormat with temporary file");
+ if (format == WebLocalStorageFormat && !cookiesEnabled) {
+ qWarning() << cookiesWarningMessage.arg("WebLocalStorageFormat");
+ format = QSettings::IniFormat;
+ } else if (format == WebIdbFormat && !cookiesEnabled) {
+ qWarning() << cookiesWarningMessage.arg("WebIdbFormat");
+ format = QSettings::IniFormat;
+ }
+
+ // Create settings backend according to selected format
+ if (format == WebLocalStorageFormat) {
+ return new QWasmLocalStorageSettingsPrivate(scope, organization, application);
+ } else if (format == WebIdbFormat) {
+ return new QWasmIDBSettingsPrivate(scope, organization, application);
+ } else if (format == QSettings::IniFormat) {
+ return new QConfFileSettingsPrivate(format, scope, organization, application);
+ }
+
+ qWarning() << "Unsupported settings format" << format;
+ return nullptr;
+}
+
QT_END_NAMESPACE
#endif // QT_NO_SETTINGS
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index ec8e6899e4..a20c50e096 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -250,7 +250,7 @@ using namespace Qt::StringLiterals;
\li "<APPROOT>/files"
\li "<APPROOT>/Documents/Desktop"
\row \li DocumentsLocation
- \li "<USER>/Documents", "<USER>/<APPNAME>/Documents"
+ \li "<USER>/Documents" [*], "<USER>/<APPNAME>/Documents"
\li "<APPROOT>/Documents"
\row \li FontsLocation
\li "/system/fonts" (not writable)
@@ -259,13 +259,13 @@ using namespace Qt::StringLiterals;
\li not supported (directory not readable)
\li not supported
\row \li MusicLocation
- \li "<USER>/Music", "<USER>/<APPNAME>/Music"
+ \li "<USER>/Music" [*], "<USER>/<APPNAME>/Music"
\li "<APPROOT>/Documents/Music"
\row \li MoviesLocation
- \li "<USER>/Movies", "<USER>/<APPNAME>/Movies"
+ \li "<USER>/Movies" [*], "<USER>/<APPNAME>/Movies"
\li "<APPROOT>/Documents/Movies"
\row \li PicturesLocation
- \li "<USER>/Pictures", "<USER>/<APPNAME>/Pictures"
+ \li "<USER>/Pictures" [*], "<USER>/<APPNAME>/Pictures"
\li "<APPROOT>/Documents/Pictures", "assets-library://"
\row \li TempLocation
\li "<APPROOT>/cache"
@@ -280,7 +280,7 @@ using namespace Qt::StringLiterals;
\li "<APPROOT>/cache", "<USER>/<APPNAME>/cache"
\li "<APPROOT>/Library/Caches"
\row \li GenericDataLocation
- \li "<USER>"
+ \li "<USER>" [*] or "<USER>/<APPNAME>/files"
\li "<APPROOT>/Library/Application Support"
\row \li RuntimeLocation
\li "<APPROOT>/cache"
@@ -292,7 +292,7 @@ using namespace Qt::StringLiterals;
\li "<APPROOT>/files/settings" (there is no shared settings)
\li "<APPROOT>/Library/Preferences"
\row \li DownloadLocation
- \li "<USER>/Downloads", "<USER>/<APPNAME>/Downloads"
+ \li "<USER>/Downloads" [*], "<USER>/<APPNAME>/Downloads"
\li "<APPROOT>/Documents/Downloads"
\row \li GenericCacheLocation
\li "<APPROOT>/cache" (there is no shared cache)
@@ -328,6 +328,11 @@ using namespace Qt::StringLiterals;
\note On Android, reading/writing to GenericDataLocation needs the READ_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE permission granted.
+ \note [*] On Android 11 and above, public directories are no longer directly accessible
+ in scoped storage mode. Thus, paths of the form \c "<USER>/DirName" are not returned.
+ Instead, you can use \l QFileDialog which uses the Storage Access Framework (SAF)
+ to access such directories.
+
\note On iOS, if you do pass \c {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}
as argument to \l{QFileDialog::setDirectory()},
a native image picker dialog will be used for accessing the user's photo album.
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp
index c26a5d30ce..a911087c9c 100644
--- a/src/corelib/io/qstandardpaths_android.cpp
+++ b/src/corelib/io/qstandardpaths_android.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qstandardpaths.h"
@@ -12,6 +12,9 @@
QT_BEGIN_NAMESPACE
+Q_DECLARE_JNI_CLASS(Environment, "android/os/Environment");
+Q_DECLARE_JNI_TYPE(File, "Ljava/io/File;");
+
using namespace QNativeInterface;
using namespace Qt::StringLiterals;
@@ -34,6 +37,48 @@ static inline QString getAbsolutePath(const QJniObject &file)
}
/*
+ * The root of the external storage
+ *
+ */
+static QString getExternalStorageDirectory()
+{
+ QString &path = (*androidDirCache)[QStringLiteral("EXT_ROOT")];
+ if (!path.isEmpty())
+ return path;
+
+ QJniObject file = QJniObject::callStaticMethod<QtJniTypes::File>("android/os/Environment",
+ "getExternalStorageDirectory");
+ if (!file.isValid())
+ return QString();
+
+ return (path = getAbsolutePath(file));
+}
+
+/*
+ * Locations where applications can place user files shared by all apps (public).
+ * E.g., /storage/Music
+ */
+static QString getExternalStoragePublicDirectory(const char *directoryField)
+{
+ QString &path = (*androidDirCache)[QLatin1String(directoryField)];
+ if (!path.isEmpty())
+ return path;
+
+ QJniObject dirField = QJniObject::getStaticField<jstring>("android/os/Environment",
+ directoryField);
+ if (!dirField.isValid())
+ return QString();
+
+ QJniObject file = QJniObject::callStaticMethod<QtJniTypes::File>("android/os/Environment",
+ "getExternalStoragePublicDirectory",
+ dirField.object<jstring>());
+ if (!file.isValid())
+ return QString();
+
+ return (path = getAbsolutePath(file));
+}
+
+/*
* Locations where applications can place persistent files it owns.
* E.g., /storage/org.app/Music
*/
@@ -132,25 +177,35 @@ static QString getFilesDir()
return (path = getAbsolutePath(file));
}
+static QString getSdkBasedExternalDir(const char *directoryField = nullptr)
+{
+ return (QNativeInterface::QAndroidApplication::sdkVersion() >= 30)
+ ? getExternalFilesDir(directoryField)
+ : getExternalStoragePublicDirectory(directoryField);
+}
+
QString QStandardPaths::writableLocation(StandardLocation type)
{
switch (type) {
case QStandardPaths::MusicLocation:
- return getExternalFilesDir("DIRECTORY_MUSIC");
+ return getSdkBasedExternalDir("DIRECTORY_MUSIC");
case QStandardPaths::MoviesLocation:
- return getExternalFilesDir("DIRECTORY_MOVIES");
+ return getSdkBasedExternalDir("DIRECTORY_MOVIES");
case QStandardPaths::PicturesLocation:
- return getExternalFilesDir("DIRECTORY_PICTURES");
+ return getSdkBasedExternalDir("DIRECTORY_PICTURES");
case QStandardPaths::DocumentsLocation:
- return getExternalFilesDir("DIRECTORY_DOCUMENTS");
+ return getSdkBasedExternalDir("DIRECTORY_DOCUMENTS");
case QStandardPaths::DownloadLocation:
- return getExternalFilesDir("DIRECTORY_DOWNLOADS");
+ return getSdkBasedExternalDir("DIRECTORY_DOWNLOADS");
case QStandardPaths::GenericConfigLocation:
case QStandardPaths::ConfigLocation:
case QStandardPaths::AppConfigLocation:
return getFilesDir() + testDir() + "/settings"_L1;
case QStandardPaths::GenericDataLocation:
- return getExternalFilesDir() + testDir();
+ {
+ return QAndroidApplication::sdkVersion() >= 30 ?
+ getExternalFilesDir() + testDir() : getExternalStorageDirectory() + testDir();
+ }
case QStandardPaths::AppDataLocation:
case QStandardPaths::AppLocalDataLocation:
return getFilesDir() + testDir();
@@ -175,59 +230,53 @@ QString QStandardPaths::writableLocation(StandardLocation type)
QStringList QStandardPaths::standardLocations(StandardLocation type)
{
- if (type == MusicLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir("DIRECTORY_MUSIC")
- << getExternalFilesDir("DIRECTORY_PODCASTS")
- << getExternalFilesDir("DIRECTORY_NOTIFICATIONS")
- << getExternalFilesDir("DIRECTORY_ALARMS");
- }
-
- if (type == MoviesLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir("DIRECTORY_MOVIES");
- }
-
- if (type == PicturesLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir("DIRECTORY_PICTURES");
- }
+ QStringList locations;
- if (type == DocumentsLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir("DIRECTORY_DOCUMENTS");
- }
-
- if (type == DownloadLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir("DIRECTORY_DOWNLOADS");
- }
-
- if (type == AppDataLocation || type == AppLocalDataLocation) {
- return QStringList() << writableLocation(type)
- << getExternalFilesDir();
- }
-
- if (type == CacheLocation) {
- return QStringList() << writableLocation(type)
- << getExternalCacheDir();
- }
-
- if (type == FontsLocation) {
+ if (type == MusicLocation) {
+ locations << getExternalFilesDir("DIRECTORY_MUSIC");
+ // Place the public dirs before the app own dirs
+ if (QNativeInterface::QAndroidApplication::sdkVersion() < 30) {
+ locations << getExternalStoragePublicDirectory("DIRECTORY_PODCASTS")
+ << getExternalStoragePublicDirectory("DIRECTORY_NOTIFICATIONS")
+ << getExternalStoragePublicDirectory("DIRECTORY_ALARMS");
+ }
+ locations << getExternalFilesDir("DIRECTORY_PODCASTS")
+ << getExternalFilesDir("DIRECTORY_NOTIFICATIONS")
+ << getExternalFilesDir("DIRECTORY_ALARMS");
+ } else if (type == MoviesLocation) {
+ locations << getExternalFilesDir("DIRECTORY_MOVIES");
+ } else if (type == PicturesLocation) {
+ locations << getExternalFilesDir("DIRECTORY_PICTURES");
+ } else if (type == DocumentsLocation) {
+ locations << getExternalFilesDir("DIRECTORY_DOCUMENTS");
+ } else if (type == DownloadLocation) {
+ locations << getExternalFilesDir("DIRECTORY_DOWNLOADS");
+ } else if (type == AppDataLocation || type == AppLocalDataLocation) {
+ locations << getExternalFilesDir();
+ } else if (type == CacheLocation) {
+ locations << getExternalCacheDir();
+ } else if (type == FontsLocation) {
QString &fontLocation = (*androidDirCache)[QStringLiteral("FONT_LOCATION")];
- if (!fontLocation.isEmpty())
- return QStringList(fontLocation);
-
- const QByteArray ba = qgetenv("QT_ANDROID_FONT_LOCATION");
- if (!ba.isEmpty())
- return QStringList((fontLocation = QDir::cleanPath(QString::fromLocal8Bit(ba))));
-
- // Don't cache the fallback, as we might just have been called before
- // QT_ANDROID_FONT_LOCATION has been set.
- return QStringList("/system/fonts"_L1);
+ if (!fontLocation.isEmpty()) {
+ locations << fontLocation;
+ } else {
+ const QByteArray ba = qgetenv("QT_ANDROID_FONT_LOCATION");
+ if (!ba.isEmpty()) {
+ locations << (fontLocation = QDir::cleanPath(QString::fromLocal8Bit(ba)));
+ } else {
+ // Don't cache the fallback, as we might just have been called before
+ // QT_ANDROID_FONT_LOCATION has been set.
+ locations << "/system/fonts"_L1;
+ }
+ }
}
- return QStringList(writableLocation(type));
+ const QString writable = writableLocation(type);
+ if (!writable.isEmpty())
+ locations.prepend(writable);
+
+ locations.removeDuplicates();
+ return locations;
}
QT_END_NAMESPACE
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index e5122ff3b6..55150f9e93 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -180,10 +180,14 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case CacheLocation:
case GenericCacheLocation:
{
+ if (isTestModeEnabled())
+ return QDir::homePath() + "/.qttest/cache"_L1;
+
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
- if (isTestModeEnabled())
- xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
+ if (!xdgCacheHome.startsWith(u'/'))
+ xdgCacheHome.clear(); // spec says relative paths should be ignored
+
if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + "/.cache"_L1;
if (type == QStandardPaths::CacheLocation)
@@ -194,9 +198,13 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case AppLocalDataLocation:
case GenericDataLocation:
{
- QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (isTestModeEnabled())
- xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
+ return QDir::homePath() + "/.qttest/share"_L1;
+
+ QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
+ if (!xdgDataHome.startsWith(u'/'))
+ xdgDataHome.clear(); // spec says relative paths should be ignored
+
if (xdgDataHome.isEmpty())
xdgDataHome = QDir::homePath() + "/.local/share"_L1;
if (type == AppDataLocation || type == AppLocalDataLocation)
@@ -207,10 +215,14 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case GenericConfigLocation:
case AppConfigLocation:
{
+ if (isTestModeEnabled())
+ return QDir::homePath() + "/.qttest/config"_L1;
+
// http://standards.freedesktop.org/basedir-spec/latest/
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
- if (isTestModeEnabled())
- xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
+ if (!xdgConfigHome.startsWith(u'/'))
+ xdgConfigHome.clear(); // spec says relative paths should be ignored
+
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + "/.config"_L1;
if (type == AppConfigLocation)
@@ -220,6 +232,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case RuntimeLocation:
{
QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
+ if (!xdgRuntimeDir.startsWith(u'/'))
+ xdgRuntimeDir.clear(); // spec says relative paths should be ignored
+
bool fromEnv = !xdgRuntimeDir.isEmpty();
if (xdgRuntimeDir.isEmpty() || !checkXdgRuntimeDir(xdgRuntimeDir)) {
// environment variable not set or is set to something unsuitable
@@ -246,6 +261,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
#if QT_CONFIG(regularexpression)
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
+ if (!xdgConfigHome.startsWith(u'/'))
+ xdgConfigHome.clear(); // spec says relative paths should be ignored
+
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + "/.config"_L1;
QFile file(xdgConfigHome + "/user-dirs.dirs"_L1);
@@ -253,23 +271,23 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (!key.isEmpty() && !isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
// Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop"
- QRegularExpression exp("^XDG_(.*)_DIR=(.*)$"_L1);
+ static const QRegularExpression exp(u"^XDG_(.*)_DIR=(.*)$"_s);
QString result;
while (!stream.atEnd()) {
const QString &line = stream.readLine();
QRegularExpressionMatch match = exp.match(line);
if (match.hasMatch() && match.capturedView(1) == key) {
QStringView value = match.capturedView(2);
- if (value.length() > 2
+ if (value.size() > 2
&& value.startsWith(u'\"')
&& value.endsWith(u'\"'))
- value = value.mid(1, value.length() - 2);
+ value = value.mid(1, value.size() - 2);
// value can start with $HOME
if (value.startsWith("$HOME"_L1))
result = QDir::homePath() + value.mid(5);
else
result = value.toString();
- if (result.length() > 1 && result.endsWith(u'/'))
+ if (result.size() > 1 && result.endsWith(u'/'))
result.chop(1);
}
}
@@ -323,41 +341,48 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return path;
}
-static QStringList xdgDataDirs()
+static QStringList dirsList(const QString &xdgEnvVar)
{
QStringList dirs;
// http://standards.freedesktop.org/basedir-spec/latest/
+ // Normalize paths, skip relative paths (the spec says relative paths
+ // should be ignored)
+ for (const auto dir : qTokenize(xdgEnvVar, u':'))
+ if (dir.startsWith(u'/'))
+ dirs.push_back(QDir::cleanPath(dir.toString()));
+
+ // Remove duplicates from the list, there's no use for duplicated
+ // paths in XDG_DATA_DIRS - if it's not found in the given
+ // directory the first time, it won't be there the second time.
+ // Plus duplicate paths causes problems for example for mimetypes,
+ // where duplicate paths here lead to duplicated mime types returned
+ // for a file, eg "text/plain,text/plain" instead of "text/plain"
+ dirs.removeDuplicates();
+
+ return dirs;
+}
+
+static QStringList xdgDataDirs()
+{
+ // http://standards.freedesktop.org/basedir-spec/latest/
QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
- if (xdgDataDirsEnv.isEmpty()) {
- dirs.append(QString::fromLatin1("/usr/local/share"));
- dirs.append(QString::fromLatin1("/usr/share"));
- } else {
- // Normalize paths, skip relative paths
- for (const auto dir : qTokenize(xdgDataDirsEnv, u':')) {
- if (dir.startsWith(u'/'))
- dirs.push_back(QDir::cleanPath(dir.toString()));
- }
- // Remove duplicates from the list, there's no use for duplicated
- // paths in XDG_DATA_DIRS - if it's not found in the given
- // directory the first time, it won't be there the second time.
- // Plus duplicate paths causes problems for example for mimetypes,
- // where duplicate paths here lead to duplicated mime types returned
- // for a file, eg "text/plain,text/plain" instead of "text/plain"
- dirs.removeDuplicates();
- }
+ QStringList dirs = dirsList(xdgDataDirsEnv);
+ if (dirs.isEmpty())
+ dirs = QStringList{u"/usr/local/share"_s, u"/usr/share"_s};
+
return dirs;
}
static QStringList xdgConfigDirs()
{
- QStringList dirs;
// http://standards.freedesktop.org/basedir-spec/latest/
const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
- if (xdgConfigDirs.isEmpty())
- dirs.append(QString::fromLatin1("/etc/xdg"));
- else
- dirs = xdgConfigDirs.split(u':');
+
+ QStringList dirs = dirsList(xdgConfigDirs);
+ if (dirs.isEmpty())
+ dirs.push_back(u"/etc/xdg"_s);
+
return dirs;
}
@@ -371,7 +396,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
break;
case AppConfigLocation:
dirs = xdgConfigDirs();
- for (int i = 0; i < dirs.count(); ++i)
+ for (int i = 0; i < dirs.size(); ++i)
appendOrganizationAndApp(dirs[i]);
break;
case GenericDataLocation:
@@ -379,19 +404,19 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
break;
case ApplicationsLocation:
dirs = xdgDataDirs();
- for (int i = 0; i < dirs.count(); ++i)
+ for (int i = 0; i < dirs.size(); ++i)
dirs[i].append("/applications"_L1);
break;
case AppDataLocation:
case AppLocalDataLocation:
dirs = xdgDataDirs();
- for (int i = 0; i < dirs.count(); ++i)
+ for (int i = 0; i < dirs.size(); ++i)
appendOrganizationAndApp(dirs[i]);
break;
case FontsLocation:
dirs += QDir::homePath() + "/.fonts"_L1;
dirs += xdgDataDirs();
- for (int i = 1; i < dirs.count(); ++i)
+ for (int i = 1; i < dirs.size(); ++i)
dirs[i].append("/fonts"_L1);
break;
default:
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 89b6dfea9d..be3bf0252d 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -451,32 +451,35 @@ inline bool QStorageIterator::next()
const char *const stop = ptr + len - 1;
// parse the line
- bool ok;
mnt.mnt_freq = 0;
mnt.mnt_passno = 0;
- mnt.mount_id = qstrntoll(ptr, stop - ptr, const_cast<const char **>(&ptr), 10, &ok);
- if (!ok)
+ auto r = qstrntoll(ptr, stop - ptr, 10);
+ if (!r.ok())
return false;
+ mnt.mount_id = r.result;
- int parent_id = qstrntoll(ptr, stop - ptr, const_cast<const char **>(&ptr), 10, &ok);
- Q_UNUSED(parent_id);
- if (!ok)
+ r = qstrntoll(r.endptr, stop - r.endptr, 10);
+ if (!r.ok())
return false;
+ int parent_id = r.result;
+ Q_UNUSED(parent_id);
- int rdevmajor = qstrntoll(ptr, stop - ptr, const_cast<const char **>(&ptr), 10, &ok);
- if (!ok)
+ r = qstrntoll(r.endptr, stop - r.endptr, 10);
+ if (!r.ok())
return false;
- if (*ptr != ':')
+ if (*r.endptr != ':')
return false;
- int rdevminor = qstrntoll(ptr + 1, stop - ptr - 1, const_cast<const char **>(&ptr), 10, &ok);
- if (!ok)
+ int rdevmajor = r.result;
+ r = qstrntoll(r.endptr + 1, stop - r.endptr - 1, 10);
+ if (!r.ok())
return false;
- mnt.rdev = makedev(rdevmajor, rdevminor);
+ mnt.rdev = makedev(rdevmajor, r.result);
- if (*ptr != ' ')
+ if (*r.endptr != ' ')
return false;
+ ptr = const_cast<char *>(r.endptr);
mnt.subvolume = ++ptr;
ptr = parseMangledPath(ptr);
if (!ptr)
@@ -711,8 +714,8 @@ void QStorageInfoPrivate::initRootPath()
const QString mountDir = it.rootPath();
const QByteArray fsName = it.fileSystemType();
// we try to find most suitable entry
- if (isParentOf(mountDir, oldRootPath) && maxLength < mountDir.length()) {
- maxLength = mountDir.length();
+ if (isParentOf(mountDir, oldRootPath) && maxLength < mountDir.size()) {
+ maxLength = mountDir.size();
rootPath = mountDir;
device = it.device();
fileSystemType = fsName;
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 44c45a1cad..86ad1439e3 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -45,7 +45,7 @@ QTemporaryFileName::QTemporaryFileName(const QString &templateName)
{
// Ensure there is a placeholder mask
QString qfilename = QDir::fromNativeSeparators(templateName);
- uint phPos = qfilename.length();
+ uint phPos = qfilename.size();
uint phLength = 0;
while (phPos != 0) {
@@ -75,7 +75,7 @@ QTemporaryFileName::QTemporaryFileName(const QString &templateName)
.nativeFilePath();
// Find mask in native path
- phPos = filename.length();
+ phPos = filename.size();
phLength = 0;
while (phPos != 0) {
--phPos;
@@ -109,8 +109,8 @@ QTemporaryFileName::QTemporaryFileName(const QString &templateName)
QFileSystemEntry::NativePath QTemporaryFileName::generateNext()
{
Q_ASSERT(length != 0);
- Q_ASSERT(pos < path.length());
- Q_ASSERT(length <= path.length() - pos);
+ Q_ASSERT(pos < path.size());
+ Q_ASSERT(length <= path.size() - pos);
Char *const placeholderStart = (Char *)path.data() + pos;
Char *const placeholderEnd = placeholderStart + length;
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index c3122e27f2..9cfa217e50 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -14,14 +14,16 @@
\ingroup network
\ingroup shared
-
It can parse and construct URLs in both encoded and unencoded
form. QUrl also has support for internationalized domain names
(IDNs).
- The most common way to use QUrl is to initialize it via the
- constructor by passing a QString. Otherwise, setUrl() can also
- be used.
+ The most common way to use QUrl is to initialize it via the constructor by
+ passing a QString containing a full URL. QUrl objects can also be created
+ from a QByteArray containing a full URL using QUrl::fromEncoded(), or
+ heuristically from incomplete URLs using QUrl::fromUserInput(). The URL
+ representation can be obtained from a QUrl using either QUrl::toString() or
+ QUrl::toEncoded().
URLs can be represented in two forms: encoded or unencoded. The
unencoded representation is suitable for showing to users, but
@@ -510,7 +512,7 @@ public:
ErrorCode validityError(QString *source = nullptr, qsizetype *position = nullptr) const;
bool validateComponent(Section section, const QString &input, qsizetype begin, qsizetype end);
bool validateComponent(Section section, const QString &input)
- { return validateComponent(section, input, 0, input.length()); }
+ { return validateComponent(section, input, 0, input.size()); }
// no QString scheme() const;
void appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
@@ -819,14 +821,16 @@ recodeFromUser(const QString &input, const ushort *actions, qsizetype from, qsiz
static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options,
const ushort *actions)
{
- // Test ComponentFormattingOptions, ignore FormattingOptions.
- if ((options & 0xFFFF0000) == QUrl::PrettyDecoded) {
+ // The stored value is already QUrl::PrettyDecoded, so there's nothing to
+ // do if that's what the user asked for (test only
+ // ComponentFormattingOptions, ignore FormattingOptions).
+ if ((options & 0xFFFF0000) == QUrl::PrettyDecoded ||
+ !qt_urlRecode(appendTo, value, options, actions))
appendTo += value;
- return;
- }
- if (!qt_urlRecode(appendTo, value, options, actions))
- appendTo += value;
+ // copy nullness, if necessary, because QString::operator+=(QStringView) doesn't
+ if (appendTo.isNull() && !value.isNull())
+ appendTo.detach();
}
inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
@@ -918,7 +922,7 @@ inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions o
}
// check if we need to remove trailing slashes
if (options & QUrl::StripTrailingSlash) {
- while (thePathView.length() > 1 && thePathView.endsWith(u'/'))
+ while (thePathView.size() > 1 && thePathView.endsWith(u'/'))
thePathView.chop(1);
}
@@ -1191,7 +1195,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar
// uppercase the version, if necessary
if (begin[2].unicode() >= 'a')
- host[host.length() - 2] = QChar{begin[2].unicode() - 0x20};
+ host[host.size() - 2] = QChar{begin[2].unicode() - 0x20};
begin += 4;
--end;
@@ -1341,7 +1345,7 @@ QUrlPrivate::setHost(const QString &value, qsizetype from, qsizetype iend, QUrl:
}
// recurse
- return setHost(s, 0, s.length(), QUrl::StrictMode);
+ return setHost(s, 0, s.size(), QUrl::StrictMode);
}
s = qt_ACE_do(value.mid(from, iend - from), NormalizeAce, ForbidLeadingDot, {});
@@ -1377,7 +1381,7 @@ inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode
qsizetype colon = -1;
qsizetype question = -1;
qsizetype hash = -1;
- const qsizetype len = url.length();
+ const qsizetype len = url.size();
const QChar *const begin = url.constData();
const ushort *const data = reinterpret_cast<const ushort *>(begin);
@@ -1628,7 +1632,7 @@ inline QUrlPrivate::ErrorCode QUrlPrivate::validityError(QString *source, qsizet
if (path.isEmpty())
return NoError;
if (path.at(0) == u'/') {
- if (hasAuthority() || path.length() == 1 || path.at(1) != u'/')
+ if (hasAuthority() || path.size() == 1 || path.at(1) != u'/')
return NoError;
if (source) {
*source = path;
@@ -1648,7 +1652,7 @@ inline QUrlPrivate::ErrorCode QUrlPrivate::validityError(QString *source, qsizet
return NoError;
// check for a path of "text:text/"
- for (qsizetype i = 0; i < path.length(); ++i) {
+ for (qsizetype i = 0; i < path.size(); ++i) {
ushort c = path.at(i).unicode();
if (c == '/') {
// found the slash before the colon
@@ -1792,7 +1796,20 @@ inline void QUrlPrivate::validate() const
/*!
- Constructs a URL by parsing \a url. QUrl will automatically percent encode
+ Constructs a URL by parsing \a url. Note this constructor expects a proper
+ URL or URL-Reference and will not attempt to guess intent. For example, the
+ following declaration:
+
+ \snippet code/src_corelib_io_qurl.cpp constructor-url-reference
+
+ Will construct a valid URL but it may not be what one expects, as the
+ scheme() part of the input is missing. For a string like the above,
+ applications may want to use fromUserInput(). For this constructor or
+ setUrl(), the following is probably what was intended:
+
+ \snippet code/src_corelib_io_qurl.cpp constructor-url
+
+ QUrl will automatically percent encode
all characters that are not allowed in a URL and decode the percent-encoded
sequences that represent an unreserved character (letters, digits, hyphens,
underscores, dots and tildes). All other characters are left in their
@@ -1956,7 +1973,7 @@ void QUrl::setScheme(const QString &scheme)
d->flags &= ~QUrlPrivate::IsLocalFile;
d->scheme.clear();
} else {
- d->setScheme(scheme, scheme.length(), /* do set error */ true);
+ d->setScheme(scheme, scheme.size(), /* do set error */ true);
}
}
@@ -2016,7 +2033,7 @@ void QUrl::setAuthority(const QString &authority, ParsingMode mode)
return;
}
- d->setAuthority(authority, 0, authority.length(), mode);
+ d->setAuthority(authority, 0, authority.size(), mode);
if (authority.isNull()) {
// QUrlPrivate::setAuthority cleared almost everything
// but it leaves the Host bit set
@@ -2087,7 +2104,7 @@ void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode)
return;
}
- d->setUserInfo(trimmed, 0, trimmed.length());
+ d->setUserInfo(trimmed, 0, trimmed.size());
if (userInfo.isNull()) {
// QUrlPrivate::setUserInfo cleared almost everything
// but it leaves the UserName bit set
@@ -2159,7 +2176,7 @@ void QUrl::setUserName(const QString &userName, ParsingMode mode)
mode = TolerantMode;
}
- d->setUserName(data, 0, data.length());
+ d->setUserName(data, 0, data.size());
if (userName.isNull())
d->sectionIsPresent &= ~QUrlPrivate::UserName;
else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::UserName, userName))
@@ -2222,7 +2239,7 @@ void QUrl::setPassword(const QString &password, ParsingMode mode)
mode = TolerantMode;
}
- d->setPassword(data, 0, data.length());
+ d->setPassword(data, 0, data.size());
if (password.isNull())
d->sectionIsPresent &= ~QUrlPrivate::Password;
else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Password, password))
@@ -2284,7 +2301,7 @@ void QUrl::setHost(const QString &host, ParsingMode mode)
mode = TolerantMode;
}
- if (d->setHost(data, 0, data.length(), mode)) {
+ if (d->setHost(data, 0, data.size(), mode)) {
if (host.isNull())
d->sectionIsPresent &= ~QUrlPrivate::Host;
} else if (!data.startsWith(u'[')) {
@@ -2293,7 +2310,7 @@ void QUrl::setHost(const QString &host, ParsingMode mode)
data.prepend(u'[');
data.append(u']');
- if (!d->setHost(data, 0, data.length(), mode)) {
+ if (!d->setHost(data, 0, data.size(), mode)) {
// failed again
if (data.contains(u':')) {
// source data contains ':', so it's an IPv6 error
@@ -2330,7 +2347,7 @@ QString QUrl::host(ComponentFormattingOptions options) const
if (d) {
d->appendHost(result, options);
if (result.startsWith(u'['))
- result = result.mid(1, result.length() - 2);
+ result = result.mid(1, result.size() - 2);
}
return result;
}
@@ -2409,7 +2426,7 @@ void QUrl::setPath(const QString &path, ParsingMode mode)
mode = TolerantMode;
}
- d->setPath(data, 0, data.length());
+ d->setPath(data, 0, data.size());
// optimized out, since there is no path delimiter
// if (path.isNull())
@@ -2545,7 +2562,7 @@ void QUrl::setQuery(const QString &query, ParsingMode mode)
mode = TolerantMode;
}
- d->setQuery(data, 0, data.length());
+ d->setQuery(data, 0, data.size());
if (query.isNull())
d->sectionIsPresent &= ~QUrlPrivate::Query;
else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Query, query))
@@ -2643,7 +2660,7 @@ void QUrl::setFragment(const QString &fragment, ParsingMode mode)
mode = TolerantMode;
}
- d->setFragment(data, 0, data.length());
+ d->setFragment(data, 0, data.size());
if (fragment.isNull())
d->sectionIsPresent &= ~QUrlPrivate::Fragment;
else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Fragment, fragment))
@@ -2937,7 +2954,7 @@ QUrl QUrl::adjusted(QUrl::FormattingOptions options) const
that.detach();
QString path;
d->appendPath(path, options | FullyEncoded, QUrlPrivate::Path);
- that.d->setPath(path, 0, path.length());
+ that.d->setPath(path, 0, path.size());
}
return that;
}
@@ -3346,7 +3363,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
QString deslashified = fromNativeSeparators(localFile);
// magic for drives on windows
- if (deslashified.length() > 1 && deslashified.at(1) == u':' && deslashified.at(0) != u'/') {
+ if (deslashified.size() > 1 && deslashified.at(1) == u':' && deslashified.at(0) != u'/') {
deslashified.prepend(u'/');
} else if (deslashified.startsWith("//"_L1)) {
// magic for shared drive on windows
@@ -3367,7 +3384,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
// Path hostname is not a valid URL host, so set it entirely in the path
// (by leaving deslashified unchanged)
} else if (indexOfPath > 2) {
- deslashified = deslashified.right(deslashified.length() - indexOfPath);
+ deslashified = deslashified.right(deslashified.size() - indexOfPath);
} else {
deslashified.clear();
}
@@ -3431,16 +3448,16 @@ bool QUrl::isParentOf(const QUrl &childUrl) const
if (!d)
return ((childUrl.scheme().isEmpty())
&& (childUrl.authority().isEmpty())
- && childPath.length() > 0 && childPath.at(0) == u'/');
+ && childPath.size() > 0 && childPath.at(0) == u'/');
QString ourPath = path();
return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme())
&& (childUrl.authority().isEmpty() || authority() == childUrl.authority())
&& childPath.startsWith(ourPath)
- && ((ourPath.endsWith(u'/') && childPath.length() > ourPath.length())
- || (!ourPath.endsWith(u'/') && childPath.length() > ourPath.length()
- && childPath.at(ourPath.length()) == u'/')));
+ && ((ourPath.endsWith(u'/') && childPath.size() > ourPath.size())
+ || (!ourPath.endsWith(u'/') && childPath.size() > ourPath.size()
+ && childPath.at(ourPath.size()) == u'/')));
}
@@ -3488,7 +3505,7 @@ QDebug operator<<(QDebug d, const QUrl &url)
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
{
- QChar c = size_t(errorPosition) < size_t(errorSource.length()) ?
+ QChar c = size_t(errorPosition) < size_t(errorSource.size()) ?
errorSource.at(errorPosition) : QChar(QChar::Null);
switch (errorCode) {
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp
index 04b9a25886..5fc6006ef4 100644
--- a/src/corelib/io/qurlidna.cpp
+++ b/src/corelib/io/qurlidna.cpp
@@ -73,11 +73,11 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output)
// Do not try to encode strings that certainly will result in output
// that is longer than allowable domain name label length. Note that
// non-BMP codepoints are encoded as two QChars.
- if (in.length() > MaxDomainLabelLength * 2)
+ if (in.size() > MaxDomainLabelLength * 2)
return;
- int outLen = output->length();
- output->resize(outLen + in.length());
+ int outLen = output->size();
+ output->resize(outLen + in.size());
QChar *d = output->data() + outLen;
bool skipped = false;
@@ -177,7 +177,7 @@ Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc)
// Do not try to decode strings longer than allowable for a domain label.
// Non-ASCII strings are not allowed here anyway, so there is no need
// to account for surrogates.
- if (pc.length() > MaxDomainLabelLength)
+ if (pc.size() > MaxDomainLabelLength)
return QString();
// strip any ACE prefix
@@ -468,7 +468,7 @@ static QString mapDomainName(const QString &in, QUrl::AceProcessingOptions optio
*/
static bool validateAsciiLabel(QStringView label)
{
- if (label.length() > MaxDomainLabelLength)
+ if (label.size() > MaxDomainLabelLength)
return false;
if (label.first() == u'-' || label.last() == u'-')
@@ -709,7 +709,7 @@ bool DomainValidityChecker::checkLabel(const QString &label, QUrl::AceProcessing
if (label != label.normalized(QString::NormalizationForm_C))
return false;
- if (label.length() >= 4) {
+ if (label.size() >= 4) {
// This assumes that the first two characters are in BMP, but that's ok
// because non-BMP characters are unlikely to be used for specifying
// future extensions.
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp
index ce8ed6414d..3cf2b1e5eb 100644
--- a/src/corelib/io/qurlquery.cpp
+++ b/src/corelib/io/qurlquery.cpp
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
improperly-encoded strings are passed to the setter or query methods,
QUrlQuery will attempt to recover instead of failing. That is to say, all
functions in this class parse their string arguments as if the
- {{QUrl::TolerantMode}} decoding mode was specified.
+ QUrl::TolerantMode decoding mode was specified.
Application code should strive to always ensure proper encoding and not rely
on TolerantMode parsing fixing the strings. Notably, all user input must be
@@ -401,7 +401,11 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const
return d->valueDelimiter == other.d->valueDelimiter &&
d->pairDelimiter == other.d->pairDelimiter &&
d->itemList == other.d->itemList;
- return false;
+
+ const QUrlQueryPrivate *x = d ? d.data() : other.d.data();
+ return x->valueDelimiter == defaultQueryValueDelimiter() &&
+ x->pairDelimiter == defaultQueryPairDelimiter() &&
+ x->itemList.isEmpty();
}
/*!
@@ -515,7 +519,7 @@ QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const
{
int size = 0;
for ( ; it != end; ++it)
- size += it->first.length() + 1 + it->second.length() + 1;
+ size += it->first.size() + 1 + it->second.size() + 1;
result.reserve(size + size / 4);
}
@@ -630,7 +634,7 @@ QList<QPair<QString, QString> > QUrlQuery::queryItems(QUrl::ComponentFormattingO
QList<QPair<QString, QString> > result;
Map::const_iterator it = d->itemList.constBegin();
Map::const_iterator end = d->itemList.constEnd();
- result.reserve(d->itemList.count());
+ result.reserve(d->itemList.size());
for ( ; it != end; ++it)
result << qMakePair(d->recodeToUser(it->first, encoding),
d->recodeToUser(it->second, encoding));
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index fcf6e69534..ecac010edb 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -713,7 +713,7 @@ QAbstractItemModel *QAbstractItemModelPrivate::staticEmptyModel()
void QAbstractItemModelPrivate::invalidatePersistentIndexes()
{
- for (QPersistentModelIndexData *data : qAsConst(persistent.indexes))
+ for (QPersistentModelIndexData *data : std::as_const(persistent.indexes))
data->index = QModelIndex();
persistent.indexes.clear();
}
@@ -840,13 +840,13 @@ void QAbstractItemModelPrivate::removePersistentIndexData(QPersistentModelIndexD
Q_UNUSED(removed);
}
// make sure our optimization still works
- for (int i = persistent.moved.count() - 1; i >= 0; --i) {
+ for (int i = persistent.moved.size() - 1; i >= 0; --i) {
int idx = persistent.moved.at(i).indexOf(data);
if (idx >= 0)
persistent.moved[i].remove(idx);
}
// update the references to invalidated persistent indexes
- for (int i = persistent.invalidated.count() - 1; i >= 0; --i) {
+ for (int i = persistent.invalidated.size() - 1; i >= 0; --i) {
int idx = persistent.invalidated.at(i).indexOf(data);
if (idx >= 0)
persistent.invalidated[i].remove(idx);
@@ -861,7 +861,7 @@ void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex &parent,
Q_UNUSED(last);
QList<QPersistentModelIndexData *> persistent_moved;
if (first < q->rowCount(parent)) {
- for (auto *data : qAsConst(persistent.indexes)) {
+ for (auto *data : std::as_const(persistent.indexes)) {
const QModelIndex &index = data->index;
if (index.row() >= first && index.isValid() && index.parent() == parent) {
persistent_moved.append(data);
@@ -897,7 +897,7 @@ void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent
const bool sameParent = (srcParent == destinationParent);
const bool movingUp = (srcFirst > destinationChild);
- for (auto *data : qAsConst(persistent.indexes)) {
+ for (auto *data : std::as_const(persistent.indexes)) {
const QModelIndex &index = data->index;
const QModelIndex &parent = index.parent();
const bool isSourceIndex = (parent == srcParent);
@@ -995,7 +995,7 @@ void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent,
QList<QPersistentModelIndexData *> persistent_invalidated;
// find the persistent indexes that are affected by the change, either by being in the removed subtree
// or by being on the same level and below the removed rows
- for (auto *data : qAsConst(persistent.indexes)) {
+ for (auto *data : std::as_const(persistent.indexes)) {
bool level_changed = false;
QModelIndex current = data->index;
while (current.isValid()) {
@@ -1047,7 +1047,7 @@ void QAbstractItemModelPrivate::columnsAboutToBeInserted(const QModelIndex &pare
Q_UNUSED(last);
QList<QPersistentModelIndexData *> persistent_moved;
if (first < q->columnCount(parent)) {
- for (auto *data : qAsConst(persistent.indexes)) {
+ for (auto *data : std::as_const(persistent.indexes)) {
const QModelIndex &index = data->index;
if (index.column() >= first && index.isValid() && index.parent() == parent)
persistent_moved.append(data);
@@ -1080,7 +1080,7 @@ void QAbstractItemModelPrivate::columnsAboutToBeRemoved(const QModelIndex &paren
QList<QPersistentModelIndexData *> persistent_invalidated;
// find the persistent indexes that are affected by the change, either by being in the removed subtree
// or by being on the same level and to the right of the removed columns
- for (auto *data : qAsConst(persistent.indexes)) {
+ for (auto *data : std::as_const(persistent.indexes)) {
bool level_changed = false;
QModelIndex current = data->index;
while (current.isValid()) {
@@ -2120,7 +2120,7 @@ QStringList QAbstractItemModel::mimeTypes() const
*/
QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const
{
- if (indexes.count() <= 0)
+ if (indexes.size() <= 0)
return nullptr;
QStringList types = mimeTypes();
if (types.isEmpty())
@@ -2159,7 +2159,7 @@ bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction a
return false;
const QStringList modelTypes = mimeTypes();
- for (int i = 0; i < modelTypes.count(); ++i) {
+ for (int i = 0; i < modelTypes.size(); ++i) {
if (data->hasFormat(modelTypes.at(i)))
return true;
}
@@ -2516,7 +2516,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
// iterates twice if wrapping
for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
- for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {
+ for (int r = from; (r < to) && (allHits || result.size() < hits); ++r) {
QModelIndex idx = index(r, column, p);
if (!idx.isValid())
continue;
@@ -2582,7 +2582,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
if (hasChildren(parent)) { // search the hierarchy
result += match(index(0, column, parent), role,
(text.isEmpty() ? value : text),
- (allHits ? -1 : hits - result.count()), flags);
+ (allHits ? -1 : hits - result.size()), flags);
}
}
}
@@ -2775,15 +2775,15 @@ bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &pare
// Compute the number of continuous rows upon insertion and modify the rows to match
QList<int> rowsToInsert(bottom + 1);
- for (int i = 0; i < rows.count(); ++i)
+ for (int i = 0; i < rows.size(); ++i)
rowsToInsert[rows.at(i)] = 1;
- for (int i = 0; i < rowsToInsert.count(); ++i) {
+ for (int i = 0; i < rowsToInsert.size(); ++i) {
if (rowsToInsert.at(i) == 1){
rowsToInsert[i] = dragRowCount;
++dragRowCount;
}
}
- for (int i = 0; i < rows.count(); ++i)
+ for (int i = 0; i < rows.size(); ++i)
rows[i] = top + rowsToInsert.at(rows.at(i));
QBitArray isWrittenTo(dragRowCount * dragColumnCount);
@@ -3446,8 +3446,8 @@ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from,
if (d->persistent.indexes.isEmpty())
return;
QList<QPersistentModelIndexData *> toBeReinserted;
- toBeReinserted.reserve(to.count());
- for (int i = 0; i < from.count(); ++i) {
+ toBeReinserted.reserve(to.size());
+ for (int i = 0; i < from.size(); ++i) {
if (from.at(i) == to.at(i))
continue;
const auto it = d->persistent.indexes.constFind(from.at(i));
@@ -3460,7 +3460,7 @@ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from,
}
}
- for (auto *data : qAsConst(toBeReinserted))
+ for (auto *data : std::as_const(toBeReinserted))
d->persistent.insertMultiAtEnd(data->index, data);
}
@@ -3473,8 +3473,8 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const
{
Q_D(const QAbstractItemModel);
QModelIndexList result;
- result.reserve(d->persistent.indexes.count());
- for (auto *data : qAsConst(d->persistent.indexes))
+ result.reserve(d->persistent.indexes.size());
+ for (auto *data : std::as_const(d->persistent.indexes))
result.append(data->index);
return result;
}
diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp
index 99324a0cd5..023587e39a 100644
--- a/src/corelib/itemmodels/qabstractproxymodel.cpp
+++ b/src/corelib/itemmodels/qabstractproxymodel.cpp
@@ -443,7 +443,7 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
{
Q_D(const QAbstractProxyModel);
QModelIndexList list;
- list.reserve(indexes.count());
+ list.reserve(indexes.size());
for (const QModelIndex &index : indexes)
list << mapToSource(index);
return d->model->mimeData(list);
diff --git a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp
index 7ef0bbc7a7..44cf28b47a 100644
--- a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp
+++ b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp
@@ -315,7 +315,7 @@ QMimeData *QConcatenateTablesProxyModel::mimeData(const QModelIndexList &indexes
Q_ASSERT(checkIndex(firstIndex, CheckIndexOption::IndexIsValid));
const auto result = d->sourceModelForRow(firstIndex.row());
QModelIndexList sourceIndexes;
- sourceIndexes.reserve(indexes.count());
+ sourceIndexes.reserve(indexes.size());
for (const QModelIndex &index : indexes) {
const QModelIndex sourceIndex = mapToSource(index);
Q_ASSERT(sourceIndex.model() == result.sourceModel); // see documentation above
@@ -688,7 +688,7 @@ void QConcatenateTablesProxyModelPrivate::updateColumnCount()
int QConcatenateTablesProxyModelPrivate::columnCountAfterChange(const QAbstractItemModel *model, int newCount) const
{
int newColumnCount = 0;
- for (int i = 0; i < m_models.count(); ++i) {
+ for (int i = 0; i < m_models.size(); ++i) {
const QAbstractItemModel *mod = m_models.at(i);
const int colCount = mod == model ? newCount : mod->columnCount();
if (i == 0)
diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp
index b610298cbb..cc0730d769 100644
--- a/src/corelib/itemmodels/qidentityproxymodel.cpp
+++ b/src/corelib/itemmodels/qidentityproxymodel.cpp
@@ -144,7 +144,7 @@ QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection&
QItemSelection::const_iterator it = selection.constBegin();
const QItemSelection::const_iterator end = selection.constEnd();
- proxySelection.reserve(selection.count());
+ proxySelection.reserve(selection.size());
for ( ; it != end; ++it) {
Q_ASSERT(it->model() == d->model);
const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
@@ -167,7 +167,7 @@ QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& s
QItemSelection::const_iterator it = selection.constBegin();
const QItemSelection::const_iterator end = selection.constEnd();
- sourceSelection.reserve(selection.count());
+ sourceSelection.reserve(selection.size());
for ( ; it != end; ++it) {
Q_ASSERT(it->model() == this);
const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
@@ -203,7 +203,7 @@ QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, c
QModelIndexList::const_iterator it = sourceList.constBegin();
const QModelIndexList::const_iterator end = sourceList.constEnd();
QModelIndexList proxyList;
- proxyList.reserve(sourceList.count());
+ proxyList.reserve(sourceList.size());
for ( ; it != end; ++it)
proxyList.append(mapFromSource(*it));
return proxyList;
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index 7da3a9b003..0f3cbadca5 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -466,15 +466,15 @@ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::Sel
if (!range.isValid())
continue;
newSelection.push_back(range);
- for (int t = 0; t < count(); ++t) {
+ for (int t = 0; t < size(); ++t) {
if (range.intersects(at(t)))
intersections.append(at(t).intersected(range));
}
}
// Split the old (and new) ranges using the intersections
- for (int i = 0; i < intersections.count(); ++i) { // for each intersection
- for (int t = 0; t < count();) { // splitt each old range
+ for (int i = 0; i < intersections.size(); ++i) { // for each intersection
+ for (int t = 0; t < size();) { // splitt each old range
if (at(t).intersects(intersections.at(i))) {
split(at(t), intersections.at(i), this);
removeAt(t);
@@ -483,7 +483,7 @@ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::Sel
}
}
// only split newSelection if Toggle is specified
- for (int n = 0; (command & QItemSelectionModel::Toggle) && n < newSelection.count();) {
+ for (int n = 0; (command & QItemSelectionModel::Toggle) && n < newSelection.size();) {
if (newSelection.at(n).intersects(intersections.at(i))) {
split(newSelection.at(n), intersections.at(i), &newSelection);
newSelection.removeAt(n);
@@ -613,7 +613,7 @@ QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection
QItemSelection expanded;
if (command & QItemSelectionModel::Rows) {
- for (int i = 0; i < selection.count(); ++i) {
+ for (int i = 0; i < selection.size(); ++i) {
QModelIndex parent = selection.at(i).parent();
int colCount = model->columnCount(parent);
QModelIndex tl = model->index(selection.at(i).top(), 0, parent);
@@ -623,7 +623,7 @@ QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection
}
}
if (command & QItemSelectionModel::Columns) {
- for (int i = 0; i < selection.count(); ++i) {
+ for (int i = 0; i < selection.size(); ++i) {
QModelIndex parent = selection.at(i).parent();
int rowCount = model->rowCount(parent);
QModelIndex tl = model->index(0, selection.at(i).left(), parent);
@@ -838,7 +838,7 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(const QList<QPersiste
// optimization for when all indexes are selected
// (only if there is lots of items (1000) because this is not entirely correct)
- if (ranges.isEmpty() && currentSelection.count() == 1) {
+ if (ranges.isEmpty() && currentSelection.size() == 1) {
QItemSelectionRange range = currentSelection.constFirst();
QModelIndex parent = range.parent();
tableRowCount = model->rowCount(parent);
@@ -878,7 +878,7 @@ static QItemSelection mergeRowLengths(const QList<QPair<QPersistentModelIndex, u
QItemSelection result;
int i = 0;
- while (i < rowLengths.count()) {
+ while (i < rowLengths.size()) {
const QPersistentModelIndex &tl = rowLengths.at(i).first;
if (!tl.isValid()) {
++i;
@@ -886,7 +886,7 @@ static QItemSelection mergeRowLengths(const QList<QPair<QPersistentModelIndex, u
}
QPersistentModelIndex br = tl;
const uint length = rowLengths.at(i).second;
- while (++i < rowLengths.count()) {
+ while (++i < rowLengths.size()) {
const QPersistentModelIndex &next = rowLengths.at(i).first;
if (!next.isValid())
continue;
@@ -916,7 +916,7 @@ static QItemSelection mergeIndexes(const QList<QPersistentModelIndex> &indexes)
QItemSelection colSpans;
// merge columns
int i = 0;
- while (i < indexes.count()) {
+ while (i < indexes.size()) {
const QPersistentModelIndex &tl = indexes.at(i);
if (!tl.isValid()) {
++i;
@@ -926,7 +926,7 @@ static QItemSelection mergeIndexes(const QList<QPersistentModelIndex> &indexes)
QModelIndex brParent = br.parent();
int brRow = br.row();
int brColumn = br.column();
- while (++i < indexes.count()) {
+ while (++i < indexes.size()) {
const QPersistentModelIndex &next = indexes.at(i);
if (!next.isValid())
continue;
@@ -949,11 +949,11 @@ static QItemSelection mergeIndexes(const QList<QPersistentModelIndex> &indexes)
// merge rows
QItemSelection rowSpans;
i = 0;
- while (i < colSpans.count()) {
+ while (i < colSpans.size()) {
QModelIndex tl = colSpans.at(i).topLeft();
QModelIndex br = colSpans.at(i).bottomRight();
QModelIndex prevTl = tl;
- while (++i < colSpans.count()) {
+ while (++i < colSpans.size()) {
QModelIndex nextTl = colSpans.at(i).topLeft();
QModelIndex nextBr = colSpans.at(i).bottomRight();
@@ -1362,7 +1362,7 @@ void QItemSelectionModel::reset()
void QItemSelectionModel::clearSelection()
{
Q_D(QItemSelectionModel);
- if (d->ranges.count() == 0 && d->currentSelection.count() == 0)
+ if (d->ranges.size() == 0 && d->currentSelection.size() == 0)
return;
select(QItemSelection(), Clear);
@@ -1433,7 +1433,7 @@ bool QItemSelectionModel::isSelected(const QModelIndex &index) const
}
// check currentSelection
- if (d->currentSelection.count()) {
+ if (d->currentSelection.size()) {
if ((d->currentCommand & Deselect) && selected)
selected = !d->currentSelection.contains(index);
else if (d->currentCommand & Toggle)
@@ -1468,8 +1468,8 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons
return false;
// return false if row exist in currentSelection (Deselect)
- if (d->currentCommand & Deselect && d->currentSelection.count()) {
- for (int i=0; i<d->currentSelection.count(); ++i) {
+ if (d->currentCommand & Deselect && d->currentSelection.size()) {
+ for (int i=0; i<d->currentSelection.size(); ++i) {
if (d->currentSelection.at(i).parent() == parent &&
row >= d->currentSelection.at(i).top() &&
row <= d->currentSelection.at(i).bottom())
@@ -1478,11 +1478,11 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons
}
// return false if ranges in both currentSelection and ranges
// intersect and have the same row contained
- if (d->currentCommand & Toggle && d->currentSelection.count()) {
- for (int i=0; i<d->currentSelection.count(); ++i)
+ if (d->currentCommand & Toggle && d->currentSelection.size()) {
+ for (int i=0; i<d->currentSelection.size(); ++i)
if (d->currentSelection.at(i).top() <= row &&
d->currentSelection.at(i).bottom() >= row)
- for (int j=0; j<d->ranges.count(); ++j)
+ for (int j=0; j<d->ranges.size(); ++j)
if (d->ranges.at(j).top() <= row && d->ranges.at(j).bottom() >= row
&& d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid())
return false;
@@ -1497,7 +1497,7 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons
// add ranges and currentSelection and check through them all
QList<QItemSelectionRange>::const_iterator it;
QList<QItemSelectionRange> joined = d->ranges;
- if (d->currentSelection.count())
+ if (d->currentSelection.size())
joined += d->currentSelection;
for (int column = 0; column < colCount; ++column) {
if (!isSelectable(row, column)) {
@@ -1542,8 +1542,8 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent
return false;
// return false if column exist in currentSelection (Deselect)
- if (d->currentCommand & Deselect && d->currentSelection.count()) {
- for (int i = 0; i < d->currentSelection.count(); ++i) {
+ if (d->currentCommand & Deselect && d->currentSelection.size()) {
+ for (int i = 0; i < d->currentSelection.size(); ++i) {
if (d->currentSelection.at(i).parent() == parent &&
column >= d->currentSelection.at(i).left() &&
column <= d->currentSelection.at(i).right())
@@ -1552,11 +1552,11 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent
}
// return false if ranges in both currentSelection and the selection model
// intersect and have the same column contained
- if (d->currentCommand & Toggle && d->currentSelection.count()) {
- for (int i = 0; i < d->currentSelection.count(); ++i) {
+ if (d->currentCommand & Toggle && d->currentSelection.size()) {
+ for (int i = 0; i < d->currentSelection.size(); ++i) {
if (d->currentSelection.at(i).left() <= column &&
d->currentSelection.at(i).right() >= column) {
- for (int j = 0; j < d->ranges.count(); ++j) {
+ for (int j = 0; j < d->ranges.size(); ++j) {
if (d->ranges.at(j).left() <= column && d->ranges.at(j).right() >= column
&& d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid()) {
return false;
@@ -1575,7 +1575,7 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent
// add ranges and currentSelection and check through them all
QList<QItemSelectionRange>::const_iterator it;
QList<QItemSelectionRange> joined = d->ranges;
- if (d->currentSelection.count())
+ if (d->currentSelection.size())
joined += d->currentSelection;
for (int row = 0; row < rowCount; ++row) {
if (!isSelectable(row, column)) {
@@ -1616,7 +1616,7 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par
QItemSelection sel = d->ranges;
sel.merge(d->currentSelection, d->currentCommand);
- for (const QItemSelectionRange &range : qAsConst(sel)) {
+ for (const QItemSelectionRange &range : std::as_const(sel)) {
if (range.parent() != parent)
return false;
int top = range.top();
@@ -1651,7 +1651,7 @@ bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelInde
QItemSelection sel = d->ranges;
sel.merge(d->currentSelection, d->currentCommand);
- for (const QItemSelectionRange &range : qAsConst(sel)) {
+ for (const QItemSelectionRange &range : std::as_const(sel)) {
if (range.parent() != parent)
return false;
int top = range.top();
@@ -1759,7 +1759,7 @@ QModelIndexList QItemSelectionModel::selectedRows(int column) const
QDuplicateTracker<RowOrColumnDefinition> rowsSeen;
const QItemSelection ranges = selection();
- for (int i = 0; i < ranges.count(); ++i) {
+ for (int i = 0; i < ranges.size(); ++i) {
const QItemSelectionRange &range = ranges.at(i);
QModelIndex parent = range.parent();
for (int row = range.top(); row <= range.bottom(); row++) {
@@ -1788,7 +1788,7 @@ QModelIndexList QItemSelectionModel::selectedColumns(int row) const
QDuplicateTracker<RowOrColumnDefinition> columnsSeen;
const QItemSelection ranges = selection();
- for (int i = 0; i < ranges.count(); ++i) {
+ for (int i = 0; i < ranges.size(); ++i) {
const QItemSelectionRange &range = ranges.at(i);
QModelIndex parent = range.parent();
for (int column = range.left(); column <= range.right(); column++) {
@@ -1911,9 +1911,9 @@ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelectio
// remove equal ranges
bool advance;
- for (int o = 0; o < deselected.count(); ++o) {
+ for (int o = 0; o < deselected.size(); ++o) {
advance = true;
- for (int s = 0; s < selected.count() && o < deselected.count();) {
+ for (int s = 0; s < selected.size() && o < deselected.size();) {
if (deselected.at(o) == selected.at(s)) {
deselected.removeAt(o);
selected.removeAt(s);
@@ -1928,17 +1928,17 @@ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelectio
// find intersections
QItemSelection intersections;
- for (int o = 0; o < deselected.count(); ++o) {
- for (int s = 0; s < selected.count(); ++s) {
+ for (int o = 0; o < deselected.size(); ++o) {
+ for (int s = 0; s < selected.size(); ++s) {
if (deselected.at(o).intersects(selected.at(s)))
intersections.append(deselected.at(o).intersected(selected.at(s)));
}
}
// compare remaining ranges with intersections and split them to find deselected and selected
- for (int i = 0; i < intersections.count(); ++i) {
+ for (int i = 0; i < intersections.size(); ++i) {
// split deselected
- for (int o = 0; o < deselected.count();) {
+ for (int o = 0; o < deselected.size();) {
if (deselected.at(o).intersects(intersections.at(i))) {
QItemSelection::split(deselected.at(o), intersections.at(i), &deselected);
deselected.removeAt(o);
@@ -1947,7 +1947,7 @@ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelectio
}
}
// split selected
- for (int s = 0; s < selected.count();) {
+ for (int s = 0; s < selected.size();) {
if (selected.at(s).intersects(intersections.at(i))) {
QItemSelection::split(selected.at(s), intersections.at(i), &selected);
selected.removeAt(s);
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
index 27cf624c51..d067edea05 100644
--- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp
+++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
@@ -450,7 +450,7 @@ bool QSortFilterProxyModelPrivate::recursiveChildAcceptsRow(int source_row, cons
void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent)
{
if (Mapping *m = source_index_mapping.take(source_parent)) {
- for (const QModelIndex &mappedIdx : qAsConst(m->mapped_children))
+ for (const QModelIndex &mappedIdx : std::as_const(m->mapped_children))
remove_from_mapping(mappedIdx);
delete m;
}
@@ -959,12 +959,12 @@ void QSortFilterProxyModelPrivate::source_items_inserted(
it = create_mapping(source_parent);
Mapping *m = it.value();
QModelIndex proxy_parent = q->mapFromSource(source_parent);
- if (m->source_rows.count() > 0) {
- q->beginInsertRows(proxy_parent, 0, m->source_rows.count() - 1);
+ if (m->source_rows.size() > 0) {
+ q->beginInsertRows(proxy_parent, 0, m->source_rows.size() - 1);
q->endInsertRows();
}
- if (m->source_columns.count() > 0) {
- q->beginInsertColumns(proxy_parent, 0, m->source_columns.count() - 1);
+ if (m->source_columns.size() > 0) {
+ q->beginInsertColumns(proxy_parent, 0, m->source_columns.size() - 1);
q->endInsertColumns();
}
return;
@@ -1175,7 +1175,7 @@ void QSortFilterProxyModelPrivate::updateChildrenMapping(const QModelIndex &sour
}
// reinsert moved, mapped indexes
- for (auto &pair : qAsConst(moved_source_index_mappings)) {
+ for (auto &pair : std::as_const(moved_source_index_mappings)) {
pair.second->source_parent = pair.first;
source_index_mapping.insert(pair.first, pair.second);
}
@@ -1190,7 +1190,7 @@ void QSortFilterProxyModelPrivate::proxy_item_range(
{
proxy_low = INT_MAX;
proxy_high = INT_MIN;
- for (int i = 0; i < source_items.count(); ++i) {
+ for (int i = 0; i < source_items.size(); ++i) {
int proxy_item = source_to_proxy.at(source_items.at(i));
Q_ASSERT(proxy_item != -1);
if (proxy_item < proxy_low)
@@ -1223,8 +1223,8 @@ QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() con
{
Q_Q(const QSortFilterProxyModel);
QModelIndexPairList source_indexes;
- source_indexes.reserve(persistent.indexes.count());
- for (const QPersistentModelIndexData *data : qAsConst(persistent.indexes)) {
+ source_indexes.reserve(persistent.indexes.size());
+ for (const QPersistentModelIndexData *data : std::as_const(persistent.indexes)) {
const QModelIndex &proxy_index = data->index;
QModelIndex source_index = q->mapToSource(proxy_index);
source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index)));
@@ -1243,7 +1243,7 @@ void QSortFilterProxyModelPrivate::update_persistent_indexes(
{
Q_Q(QSortFilterProxyModel);
QModelIndexList from, to;
- const int numSourceIndexes = source_indexes.count();
+ const int numSourceIndexes = source_indexes.size();
from.reserve(numSourceIndexes);
to.reserve(numSourceIndexes);
for (const auto &indexPair : source_indexes) {
@@ -1327,7 +1327,7 @@ QSet<int> QSortFilterProxyModelPrivate::handle_filter_changed(
Q_Q(QSortFilterProxyModel);
// Figure out which mapped items to remove
QList<int> source_items_remove;
- for (int i = 0; i < proxy_to_source.count(); ++i) {
+ for (int i = 0; i < proxy_to_source.size(); ++i) {
const int source_item = proxy_to_source.at(i);
if ((orient == Qt::Vertical)
? !filterAcceptsRowInternal(source_item, source_parent)
@@ -1435,7 +1435,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
QList<int> source_rows_insert;
QList<int> source_rows_change;
QList<int> source_rows_resort;
- int end = qMin(source_bottom_right.row(), m->proxy_rows.count() - 1);
+ int end = qMin(source_bottom_right.row(), m->proxy_rows.size() - 1);
for (int source_row = source_top_left.row(); source_row <= end; ++source_row) {
if (dynamic_sortfilter && !change_in_unmapped_parent) {
if (m->proxy_rows.at(source_row) != -1) {
@@ -2155,7 +2155,7 @@ QModelIndex QSortFilterProxyModel::index(int row, int column, const QModelIndex
QModelIndex source_parent = mapToSource(parent); // parent is already mapped at this point
IndexMap::const_iterator it = d->create_mapping(source_parent); // but make sure that the children are mapped
- if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
+ if (it.value()->source_rows.size() <= row || it.value()->source_columns.size() <= column)
return QModelIndex();
return d->create_index(row, column, it);
@@ -2186,7 +2186,7 @@ QModelIndex QSortFilterProxyModel::sibling(int row, int column, const QModelInde
return QModelIndex();
const IndexMap::const_iterator it = d->index_to_iterator(idx);
- if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
+ if (it.value()->source_rows.size() <= row || it.value()->source_columns.size() <= column)
return QModelIndex();
return d->create_index(row, column, it);
@@ -2202,7 +2202,7 @@ int QSortFilterProxyModel::rowCount(const QModelIndex &parent) const
if (parent.isValid() && !source_parent.isValid())
return 0;
IndexMap::const_iterator it = d->create_mapping(source_parent);
- return it.value()->source_rows.count();
+ return it.value()->source_rows.size();
}
/*!
@@ -2215,7 +2215,7 @@ int QSortFilterProxyModel::columnCount(const QModelIndex &parent) const
if (parent.isValid() && !source_parent.isValid())
return 0;
IndexMap::const_iterator it = d->create_mapping(source_parent);
- return it.value()->source_columns.count();
+ return it.value()->source_columns.size();
}
/*!
@@ -2234,7 +2234,7 @@ bool QSortFilterProxyModel::hasChildren(const QModelIndex &parent) const
return true; //we assume we might have children that can be fetched
QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
- return m->source_rows.count() != 0 && m->source_columns.count() != 0;
+ return m->source_rows.size() != 0 && m->source_columns.size() != 0;
}
/*!
@@ -2268,15 +2268,15 @@ QVariant QSortFilterProxyModel::headerData(int section, Qt::Orientation orientat
{
Q_D(const QSortFilterProxyModel);
IndexMap::const_iterator it = d->create_mapping(QModelIndex());
- if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
+ if (it.value()->source_rows.size() * it.value()->source_columns.size() > 0)
return QAbstractProxyModel::headerData(section, orientation, role);
int source_section;
if (orientation == Qt::Vertical) {
- if (section < 0 || section >= it.value()->source_rows.count())
+ if (section < 0 || section >= it.value()->source_rows.size())
return QVariant();
source_section = it.value()->source_rows.at(section);
} else {
- if (section < 0 || section >= it.value()->source_columns.count())
+ if (section < 0 || section >= it.value()->source_columns.size())
return QVariant();
source_section = it.value()->source_columns.at(section);
}
@@ -2291,15 +2291,15 @@ bool QSortFilterProxyModel::setHeaderData(int section, Qt::Orientation orientati
{
Q_D(QSortFilterProxyModel);
IndexMap::const_iterator it = d->create_mapping(QModelIndex());
- if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
+ if (it.value()->source_rows.size() * it.value()->source_columns.size() > 0)
return QAbstractProxyModel::setHeaderData(section, orientation, value, role);
int source_section;
if (orientation == Qt::Vertical) {
- if (section < 0 || section >= it.value()->source_rows.count())
+ if (section < 0 || section >= it.value()->source_rows.size())
return false;
source_section = it.value()->source_rows.at(section);
} else {
- if (section < 0 || section >= it.value()->source_columns.count())
+ if (section < 0 || section >= it.value()->source_columns.size())
return false;
source_section = it.value()->source_columns.at(section);
}
@@ -2313,7 +2313,7 @@ QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const
{
Q_D(const QSortFilterProxyModel);
QModelIndexList source_indexes;
- source_indexes.reserve(indexes.count());
+ source_indexes.reserve(indexes.size());
for (const QModelIndex &idx : indexes)
source_indexes << mapToSource(idx);
return d->model->mimeData(source_indexes);
@@ -2359,10 +2359,10 @@ bool QSortFilterProxyModel::insertRows(int row, int count, const QModelIndex &pa
if (parent.isValid() && !source_parent.isValid())
return false;
QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
- if (row > m->source_rows.count())
+ if (row > m->source_rows.size())
return false;
- int source_row = (row >= m->source_rows.count()
- ? m->proxy_rows.count()
+ int source_row = (row >= m->source_rows.size()
+ ? m->proxy_rows.size()
: m->source_rows.at(row));
return d->model->insertRows(source_row, count, source_parent);
}
@@ -2379,10 +2379,10 @@ bool QSortFilterProxyModel::insertColumns(int column, int count, const QModelInd
if (parent.isValid() && !source_parent.isValid())
return false;
QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
- if (column > m->source_columns.count())
+ if (column > m->source_columns.size())
return false;
- int source_column = (column >= m->source_columns.count()
- ? m->proxy_columns.count()
+ int source_column = (column >= m->source_columns.size()
+ ? m->proxy_columns.size()
: m->source_columns.at(column));
return d->model->insertColumns(source_column, count, source_parent);
}
@@ -2399,10 +2399,10 @@ bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &pa
if (parent.isValid() && !source_parent.isValid())
return false;
QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
- if (row + count > m->source_rows.count())
+ if (row + count > m->source_rows.size())
return false;
if ((count == 1)
- || ((d->source_sort_column < 0) && (m->proxy_rows.count() == m->source_rows.count()))) {
+ || ((d->source_sort_column < 0) && (m->proxy_rows.size() == m->source_rows.size()))) {
int source_row = m->source_rows.at(row);
return d->model->removeRows(source_row, count, source_parent);
}
@@ -2414,7 +2414,7 @@ bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &pa
rows.append(m->source_rows.at(i));
std::sort(rows.begin(), rows.end());
- int pos = rows.count() - 1;
+ int pos = rows.size() - 1;
bool ok = true;
while (pos >= 0) {
const int source_end = rows.at(pos--);
@@ -2441,9 +2441,9 @@ bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelInd
if (parent.isValid() && !source_parent.isValid())
return false;
QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
- if (column + count > m->source_columns.count())
+ if (column + count > m->source_columns.size())
return false;
- if ((count == 1) || (m->proxy_columns.count() == m->source_columns.count())) {
+ if ((count == 1) || (m->proxy_columns.size() == m->source_columns.size())) {
int source_column = m->source_columns.at(column);
return d->model->removeColumns(source_column, count, source_parent);
}
@@ -2453,7 +2453,7 @@ bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelInd
for (int i = column; i < column + count; ++i)
columns.append(m->source_columns.at(i));
- int pos = columns.count() - 1;
+ int pos = columns.size() - 1;
bool ok = true;
while (pos >= 0) {
const int source_end = columns.at(pos--);
diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp
index 8d409f46a0..002f500263 100644
--- a/src/corelib/itemmodels/qstringlistmodel.cpp
+++ b/src/corelib/itemmodels/qstringlistmodel.cpp
@@ -86,7 +86,7 @@ int QStringListModel::rowCount(const QModelIndex &parent) const
if (parent.isValid())
return 0;
- return lst.count();
+ return lst.size();
}
/*!
@@ -94,7 +94,7 @@ int QStringListModel::rowCount(const QModelIndex &parent) const
*/
QModelIndex QStringListModel::sibling(int row, int column, const QModelIndex &idx) const
{
- if (!idx.isValid() || column != 0 || row >= lst.count() || row < 0)
+ if (!idx.isValid() || column != 0 || row >= lst.size() || row < 0)
return QModelIndex();
return createIndex(row, 0);
@@ -310,7 +310,7 @@ void QStringListModel::sort(int, Qt::SortOrder order)
emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);
QList<QPair<QString, int>> list;
- const int lstCount = lst.count();
+ const int lstCount = lst.size();
list.reserve(lstCount);
for (int i = 0; i < lstCount; ++i)
list.append(QPair<QString, int>(lst.at(i), i));
@@ -329,7 +329,7 @@ void QStringListModel::sort(int, Qt::SortOrder order)
QModelIndexList oldList = persistentIndexList();
QModelIndexList newList;
- const int numOldIndexes = oldList.count();
+ const int numOldIndexes = oldList.size();
newList.reserve(numOldIndexes);
for (int i = 0; i < numOldIndexes; ++i)
newList.append(index(forwarding.at(oldList.at(i).row()), 0));
diff --git a/src/corelib/itemmodels/qtransposeproxymodel.cpp b/src/corelib/itemmodels/qtransposeproxymodel.cpp
index 96343674b8..621b54782e 100644
--- a/src/corelib/itemmodels/qtransposeproxymodel.cpp
+++ b/src/corelib/itemmodels/qtransposeproxymodel.cpp
@@ -32,7 +32,7 @@ void QTransposeProxyModelPrivate::onLayoutChanged(const QList<QPersistentModelIn
Q_ASSERT(layoutChangeProxyIndexes.size() == layoutChangePersistentIndexes.size());
QModelIndexList toList;
toList.reserve(layoutChangePersistentIndexes.size());
- for (const QPersistentModelIndex &persistIdx : qAsConst(layoutChangePersistentIndexes))
+ for (const QPersistentModelIndex &persistIdx : std::as_const(layoutChangePersistentIndexes))
toList << q->mapFromSource(persistIdx);
q->changePersistentIndexList(layoutChangeProxyIndexes, toList);
layoutChangeProxyIndexes.clear();
@@ -172,7 +172,7 @@ void QTransposeProxyModel::setSourceModel(QAbstractItemModel* newSourceModel)
return;
beginResetModel();
if (d->model) {
- for (const QMetaObject::Connection& discIter : qAsConst(d->sourceConnections))
+ for (const QMetaObject::Connection& discIter : std::as_const(d->sourceConnections))
disconnect(discIter);
}
d->sourceConnections.clear();
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp
index 84a688a9e4..3001e3269b 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.cpp
+++ b/src/corelib/kernel/qabstracteventdispatcher.cpp
@@ -382,7 +382,7 @@ void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilt
void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
{
Q_D(QAbstractEventDispatcher);
- for (int i = 0; i < d->eventFilters.count(); ++i) {
+ for (int i = 0; i < d->eventFilters.size(); ++i) {
if (d->eventFilters.at(i) == filter) {
d->eventFilters[i] = nullptr;
break;
diff --git a/src/corelib/kernel/qapplicationstatic.h b/src/corelib/kernel/qapplicationstatic.h
index d2e050a911..2f2cab9174 100644
--- a/src/corelib/kernel/qapplicationstatic.h
+++ b/src/corelib/kernel/qapplicationstatic.h
@@ -9,6 +9,8 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qglobalstatic.h>
+#include <new>
+
QT_BEGIN_NAMESPACE
namespace QtGlobalStatic {
@@ -17,7 +19,7 @@ template <typename QAS> struct ApplicationHolder
using Type = typename QAS::QAS_Type;
using PlainType = std::remove_cv_t<Type>;
- Q_CONSTINIT static inline std::aligned_union_t<1, PlainType> storage = {};
+ Q_CONSTINIT static inline struct { alignas(Type) unsigned char data[sizeof(Type)]; } storage = {};
Q_CONSTINIT static inline QBasicAtomicInteger<qint8> guard = { QtGlobalStatic::Uninitialized };
Q_CONSTINIT static inline QBasicMutex mutex {};
@@ -36,7 +38,7 @@ template <typename QAS> struct ApplicationHolder
static PlainType *realPointer()
{
- return reinterpret_cast<PlainType *>(&storage);
+ return std::launder(reinterpret_cast<PlainType *>(&storage));
}
// called from QGlobalStatic::instance()
@@ -46,7 +48,7 @@ template <typename QAS> struct ApplicationHolder
return realPointer();
QMutexLocker locker(&mutex);
if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) {
- QAS::innerFunction(realPointer());
+ QAS::innerFunction(&storage);
QObject::connect(QCoreApplication::instance(), &QObject::destroyed, reset);
guard.storeRelaxed(QtGlobalStatic::Initialized);
}
diff --git a/src/corelib/kernel/qcfsocketnotifier.cpp b/src/corelib/kernel/qcfsocketnotifier.cpp
index 99f66170f3..21a22a7439 100644
--- a/src/corelib/kernel/qcfsocketnotifier.cpp
+++ b/src/corelib/kernel/qcfsocketnotifier.cpp
@@ -213,7 +213,7 @@ void QCFSocketNotifier::unregisterSocketNotifier(QSocketNotifier *notifier)
void QCFSocketNotifier::removeSocketNotifiers()
{
// Remove CFSockets from the runloop.
- for (MacSocketInfo *socketInfo : qAsConst(macSockets)) {
+ for (MacSocketInfo *socketInfo : std::as_const(macSockets)) {
unregisterSocketInfo(socketInfo);
delete socketInfo;
}
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm
index b18a7d56ef..9b5a073993 100644
--- a/src/corelib/kernel/qcore_mac.mm
+++ b/src/corelib/kernel/qcore_mac.mm
@@ -255,16 +255,9 @@ QMacAutoReleasePool::QMacAutoReleasePool()
#ifdef QT_DEBUG
void *poolFrame = nullptr;
- if (__builtin_available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 5.0, *)) {
- void *frame;
- if (backtrace_from_fp(__builtin_frame_address(0), &frame, 1))
- poolFrame = frame;
- } else {
- static const int maxFrames = 3;
- void *callstack[maxFrames];
- if (backtrace(callstack, maxFrames) == maxFrames)
- poolFrame = callstack[maxFrames - 1];
- }
+ void *frame;
+ if (backtrace_from_fp(__builtin_frame_address(0), &frame, 1))
+ poolFrame = frame;
if (poolFrame) {
Dl_info info;
@@ -335,14 +328,9 @@ QDebug operator<<(QDebug debug, const QCFString &string)
#ifdef Q_OS_MACOS
bool qt_mac_applicationIsInDarkMode()
{
-#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
- if (__builtin_available(macOS 10.14, *)) {
- auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
- @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
- return [appearance isEqualToString:NSAppearanceNameDarkAqua];
- }
-#endif
- return false;
+ auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
+ @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
+ return [appearance isEqualToString:NSAppearanceNameDarkAqua];
}
bool qt_mac_runningUnderRosetta()
@@ -426,8 +414,7 @@ void qt_mac_ensureResponsible()
CHECK_SPAWN(posix_spawnattr_setflags(&attr, flags));
- if (@available(macOS 10.14, *))
- CHECK_SPAWN(responsibility_spawnattrs_setdisclaim(&attr, 1));
+ CHECK_SPAWN(responsibility_spawnattrs_setdisclaim(&attr, 1));
char **argv = *_NSGetArgv();
posix_spawnp(&pid, argv[0], nullptr, &attr, argv, environ);
@@ -562,10 +549,18 @@ void qt_apple_check_os_version()
const char *os = "macOS";
const int version = __MAC_OS_X_VERSION_MIN_REQUIRED;
#endif
- const NSOperatingSystemVersion required = (NSOperatingSystemVersion){
- version / 10000, version / 100 % 100, version % 100};
- const NSOperatingSystemVersion current = NSProcessInfo.processInfo.operatingSystemVersion;
- if (![NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:required]) {
+
+ const auto required = QVersionNumber(version / 10000, version / 100 % 100, version % 100);
+ const auto current = QOperatingSystemVersion::current().version();
+
+#if defined(Q_OS_MACOS)
+ // Check for compatibility version, in which case we can't do a
+ // comparison to the deployment target, which might be e.g. 11.0
+ if (current.majorVersion() == 10 && current.minorVersion() >= 16)
+ return;
+#endif
+
+ if (current < required) {
NSDictionary *plist = NSBundle.mainBundle.infoDictionary;
NSString *applicationName = plist[@"CFBundleDisplayName"];
if (!applicationName)
@@ -576,8 +571,8 @@ void qt_apple_check_os_version()
fprintf(stderr, "Sorry, \"%s\" cannot be run on this version of %s. "
"Qt requires %s %ld.%ld.%ld or later, you have %s %ld.%ld.%ld.\n",
applicationName.UTF8String, os,
- os, long(required.majorVersion), long(required.minorVersion), long(required.patchVersion),
- os, long(current.majorVersion), long(current.minorVersion), long(current.patchVersion));
+ os, long(required.majorVersion()), long(required.minorVersion()), long(required.microVersion()),
+ os, long(current.majorVersion()), long(current.minorVersion()), long(current.microVersion()));
exit(1);
}
@@ -711,11 +706,9 @@ QMacVersion::VersionTuple QMacVersion::versionsForImage(const mach_header *machH
|| loadCommand->cmd == LC_VERSION_MIN_TVOS || loadCommand->cmd == LC_VERSION_MIN_WATCHOS) {
auto versionCommand = reinterpret_cast<version_min_command *>(loadCommand);
return makeVersionTuple(versionCommand->version, versionCommand->sdk, osForLoadCommand(loadCommand->cmd));
-#if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13, __IPHONE_11_0, __TVOS_11_0, __WATCHOS_4_0)
} else if (loadCommand->cmd == LC_BUILD_VERSION) {
auto versionCommand = reinterpret_cast<build_version_command *>(loadCommand);
return makeVersionTuple(versionCommand->minos, versionCommand->sdk, osForPlatform(versionCommand->platform));
-#endif
}
commandCursor += loadCommand->cmdsize;
}
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 54bbbc1e39..7695bd29a8 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -275,8 +275,8 @@ public:
void swap(QAppleLogActivity &other)
{
- qSwap(activity, other.activity);
- qSwap(state, other.state);
+ activity.swap(other.activity);
+ std::swap(state, other.state);
}
private:
@@ -333,7 +333,7 @@ public:
void swap(QMacNotificationObserver &other) noexcept
{
- qSwap(observer, other.observer);
+ qt_ptr_swap(observer, other.observer);
}
void remove();
@@ -383,9 +383,9 @@ public:
void swap(QMacKeyValueObserver &other) noexcept
{
- qSwap(object, other.object);
- qSwap(keyPath, other.keyPath);
- qSwap(callback, other.callback);
+ qt_ptr_swap(object, other.object);
+ qt_ptr_swap(keyPath, other.keyPath);
+ callback.swap(other.callback);
}
private:
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 4d69ca9a17..7f53931a3d 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -31,6 +31,7 @@
#include <private/qthread_p.h>
#if QT_CONFIG(thread)
#include <qthreadpool.h>
+#include <private/qthreadpool_p.h>
#endif
#endif
#include <qelapsedtimer.h>
@@ -302,7 +303,7 @@ void Q_CORE_EXPORT qt_call_post_routines()
if (list.isEmpty())
break;
- for (QtCleanUpFunction f : qAsConst(list))
+ for (QtCleanUpFunction f : std::as_const(list))
f();
}
}
@@ -547,24 +548,47 @@ QString qAppName()
void QCoreApplicationPrivate::initLocale()
{
-#if defined(Q_OS_UNIX) && !defined(QT_BOOTSTRAPPED)
+#if defined(QT_BOOTSTRAPPED)
+ // Don't try to control bootstrap library locale or encoding.
+#elif defined(Q_OS_UNIX)
Q_CONSTINIT static bool qt_locale_initialized = false;
if (qt_locale_initialized)
return;
qt_locale_initialized = true;
-#ifdef Q_OS_INTEGRITY
+ // By default the portable "C"/POSIX locale is selected and active.
+ // Apply the locale from the environment, via setlocale(), which will
+ // read LC_ALL, LC_<category>, and LANG, in order (for each category).
+ setlocale(LC_ALL, "");
+
+ // Next, let's ensure that LC_CTYPE is UTF-8, since QStringConverter's
+ // QLocal8Bit hard-codes this, and we need to be consistent.
+# if defined(Q_OS_INTEGRITY)
setlocale(LC_CTYPE, "UTF-8");
-#else
- // Android's Bionic didn't get nl_langinfo until NDK 15 (Android 8.0),
- // which is too new for Qt, so we just assume it's always UTF-8.
- auto nl_langinfo = [](int) { return "UTF-8"; };
-
- const char *locale = setlocale(LC_ALL, "");
- const char *codec = nl_langinfo(CODESET);
- if (Q_UNLIKELY(strcmp(codec, "UTF-8") != 0 && strcmp(codec, "utf8") != 0)) {
- QByteArray oldLocale = locale;
- QByteArray newLocale = setlocale(LC_CTYPE, nullptr);
+# elif defined(Q_OS_QNX)
+ // QNX has no nl_langinfo, so we can't check.
+ // FIXME: Shouldn't we still setlocale("UTF-8")?
+# elif defined(Q_OS_ANDROID) && __ANDROID_API__ < __ANDROID_API_O__
+ // Android 6 still lacks nl_langinfo(), so we can't check.
+ // FIXME: Shouldn't we still setlocale("UTF-8")?
+# else
+ const char *charEncoding = nl_langinfo(CODESET);
+ if (Q_UNLIKELY(qstricmp(charEncoding, "UTF-8") != 0 && qstricmp(charEncoding, "utf8") != 0)) {
+ const QByteArray oldLocale = setlocale(LC_ALL, nullptr);
+ QByteArray newLocale;
+ bool warnOnOverride = true;
+# if defined(Q_OS_DARWIN)
+ // Don't warn unless the char encoding has been changed from the
+ // default "C" encoding, or the user touched any of the locale
+ // environment variables to force the "C" char encoding.
+ warnOnOverride = qstrcmp(setlocale(LC_CTYPE, nullptr), "C") != 0
+ || getenv("LC_ALL") || getenv("LC_CTYPE") || getenv("LANG");
+
+ // No need to try language or region specific CTYPEs, as they
+ // all point back to the same generic UTF-8 CTYPE.
+ newLocale = setlocale(LC_CTYPE, "UTF-8");
+# else
+ newLocale = setlocale(LC_CTYPE, nullptr);
if (qsizetype dot = newLocale.indexOf('.'); dot != -1)
newLocale.truncate(dot); // remove encoding, if any
if (qsizetype at = newLocale.indexOf('@'); at != -1)
@@ -572,23 +596,30 @@ void QCoreApplicationPrivate::initLocale()
newLocale += ".UTF-8";
newLocale = setlocale(LC_CTYPE, newLocale);
- // if locale doesn't exist, try some fallbacks
-# ifdef Q_OS_DARWIN
- if (newLocale.isEmpty())
- newLocale = setlocale(LC_CTYPE, "UTF-8");
-# endif
+ // If that locale doesn't exist, try some fallbacks:
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "C.UTF-8");
if (newLocale.isEmpty())
newLocale = setlocale(LC_CTYPE, "C.utf8");
-
- qWarning("Detected system locale encoding (%s, locale \"%s\") is not UTF-8.\n"
- "Qt shall use a UTF-8 locale (\"%s\") instead. If this causes problems,\n"
- "reconfigure your locale. See the locale(1) manual for more information.",
- codec, oldLocale.constData(), newLocale.constData());
+# endif
+
+ if (newLocale.isEmpty()) {
+ // Failed to set a UTF-8 locale.
+ qWarning("Detected locale \"%s\" with character encoding \"%s\", which is not UTF-8.\n"
+ "Qt depends on a UTF-8 locale, but has failed to switch to one.\n"
+ "If this causes problems, reconfigure your locale. See the locale(1) manual\n"
+ "for more information.", oldLocale.constData(), charEncoding);
+ } else if (warnOnOverride) {
+ // Let the user know we over-rode their configuration.
+ qWarning("Detected locale \"%s\" with character encoding \"%s\", which is not UTF-8.\n"
+ "Qt depends on a UTF-8 locale, and has switched to \"%s\" instead.\n"
+ "If this causes problems, reconfigure your locale. See the locale(1) manual\n"
+ "for more information.",
+ oldLocale.constData(), charEncoding, newLocale.constData());
+ }
}
-#endif
-#endif
+# endif // Platform choice
+#endif // Unix
}
@@ -783,7 +814,7 @@ void QCoreApplicationPrivate::init()
// have been removed. Once the original list is exhausted we know all the remaining
// items have been added.
QStringList newPaths(q->libraryPaths());
- for (qsizetype i = manualPaths->length(), j = appPaths->length(); i > 0 || j > 0; qt_noop()) {
+ for (qsizetype i = manualPaths->size(), j = appPaths->size(); i > 0 || j > 0; qt_noop()) {
if (--j < 0) {
newPaths.prepend((*manualPaths)[--i]);
} else if (--i < 0) {
@@ -853,8 +884,10 @@ QCoreApplication::~QCoreApplication()
#if QT_CONFIG(thread)
// Synchronize and stop the global thread pool threads.
QThreadPool *globalThreadPool = nullptr;
+ QThreadPool *guiThreadPool = nullptr;
QT_TRY {
globalThreadPool = QThreadPool::globalInstance();
+ guiThreadPool = QThreadPoolPrivate::qtGuiInstance();
} QT_CATCH (...) {
// swallow the exception, since destructors shouldn't throw
}
@@ -862,6 +895,10 @@ QCoreApplication::~QCoreApplication()
globalThreadPool->waitForDone();
delete globalThreadPool;
}
+ if (guiThreadPool) {
+ guiThreadPool->waitForDone();
+ delete guiThreadPool;
+ }
#endif
#ifndef QT_NO_QOBJECT
@@ -2138,12 +2175,12 @@ static void replacePercentN(QString *result, int n)
qsizetype len = 0;
while ((percentPos = result->indexOf(u'%', percentPos + len)) != -1) {
len = 1;
- if (percentPos + len == result->length())
+ if (percentPos + len == result->size())
break;
QString fmt;
if (result->at(percentPos + len) == u'L') {
++len;
- if (percentPos + len == result->length())
+ if (percentPos + len == result->size())
break;
fmt = "%L1"_L1;
} else {
@@ -2153,7 +2190,7 @@ static void replacePercentN(QString *result, int n)
fmt = fmt.arg(n);
++len;
result->replace(percentPos, len, fmt);
- len = fmt.length();
+ len = fmt.size();
}
}
}
diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h
index 2220f5dcef..980a2866e0 100644
--- a/src/corelib/kernel/qdeadlinetimer.h
+++ b/src/corelib/kernel/qdeadlinetimer.h
@@ -16,9 +16,7 @@
#include <limits>
-#if __has_include(<chrono>)
-# include <chrono>
-#endif
+#include <chrono>
QT_BEGIN_NAMESPACE
@@ -84,7 +82,6 @@ public:
QDeadlineTimer &operator-=(qint64 msecs)
{ *this = *this + (-msecs); return *this; }
-#if __has_include(<chrono>) || defined(Q_CLANG_QDOC)
template <class Clock, class Duration>
QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline_,
Qt::TimerType type_ = Qt::CoarseTimer) : t2(0)
@@ -142,7 +139,6 @@ public:
template <class Rep, class Period>
friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration<Rep, Period> value)
{ return dt = dt + value; }
-#endif
private:
qint64 t1;
@@ -156,7 +152,7 @@ public:
QPair<qint64, unsigned> _q_data() const { return qMakePair(t1, t2); }
};
-#if __has_include(<chrono>) && (defined(Q_OS_DARWIN) || defined(Q_OS_LINUX) || (defined(Q_CC_MSVC) && Q_CC_MSVC >= 1900))
+#if defined(Q_OS_DARWIN) || defined(Q_OS_LINUX) || (defined(Q_CC_MSVC) && Q_CC_MSVC >= 1900)
// We know for these OS/compilers that the std::chrono::steady_clock uses the same
// reference time as QDeadlineTimer
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp
index b5bd21c8ab..c644dd35d8 100644
--- a/src/corelib/kernel/qeventdispatcher_glib.cpp
+++ b/src/corelib/kernel/qeventdispatcher_glib.cpp
@@ -41,7 +41,7 @@ static gboolean socketNotifierSourceCheck(GSource *source)
GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
bool pending = false;
- for (int i = 0; !pending && i < src->pollfds.count(); ++i) {
+ for (int i = 0; !pending && i < src->pollfds.size(); ++i) {
GPollFDWithQSocketNotifier *p = src->pollfds.at(i);
if (p->pollfd.revents & G_IO_NVAL) {
@@ -65,7 +65,7 @@ static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpoin
QEvent event(QEvent::SockAct);
GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
- for (src->activeNotifierPos = 0; src->activeNotifierPos < src->pollfds.count();
+ for (src->activeNotifierPos = 0; src->activeNotifierPos < src->pollfds.size();
++src->activeNotifierPos) {
GPollFDWithQSocketNotifier *p = src->pollfds.at(src->activeNotifierPos);
@@ -348,7 +348,7 @@ QEventDispatcherGlib::~QEventDispatcherGlib()
d->idleTimerSource = nullptr;
// destroy socket notifier source
- for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {
+ for (int i = 0; i < d->socketNotifierSource->pollfds.size(); ++i) {
GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i];
g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);
delete p;
@@ -458,7 +458,7 @@ void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier)
Q_D(QEventDispatcherGlib);
- for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {
+ for (int i = 0; i < d->socketNotifierSource->pollfds.size(); ++i) {
GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i);
if (p->socketNotifier == notifier) {
// found it
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index 94ed8c74ad..ad515c2eec 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -216,7 +216,7 @@ int QEventDispatcherUNIXPrivate::activateTimers()
void QEventDispatcherUNIXPrivate::markPendingSocketNotifiers()
{
- for (const pollfd &pfd : qAsConst(pollfds)) {
+ for (const pollfd &pfd : std::as_const(pollfds)) {
if (pfd.fd < 0 || pfd.revents == 0)
continue;
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp
index c733f46c14..73f468aae5 100644
--- a/src/corelib/kernel/qeventdispatcher_wasm.cpp
+++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp
@@ -26,14 +26,16 @@ Q_LOGGING_CATEGORY(lcEventDispatcherTimers, "qt.eventdispatcher.timers");
#define LOCK_GUARD(M)
#endif
-#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
-
// Emscripten asyncify currently supports one level of suspend -
// recursion is not permitted. We track the suspend state here
// on order to fail (more) gracefully, but we can of course only
// track Qts own usage of asyncify.
static bool g_is_asyncify_suspended = false;
+EM_JS(bool, qt_have_asyncify_js, (), {
+ return typeof Asyncify != "undefined";
+});
+
EM_JS(void, qt_asyncify_suspend_js, (), {
let sleepFn = (wakeUp) => {
Module.qtAsyncifyWakeUp = wakeUp;
@@ -52,6 +54,15 @@ EM_JS(void, qt_asyncify_resume_js, (), {
setTimeout(wakeUp);
});
+// Returns true if asyncify is available.
+bool qt_have_asyncify()
+{
+ static bool have_asyncify = []{
+ return qt_have_asyncify_js();
+ }();
+ return have_asyncify;
+}
+
// Suspends the main thread until qt_asyncify_resume() is called. Returns
// false immediately if Qt has already suspended the main thread (recursive
// suspend is not supported by Emscripten). Returns true (after resuming),
@@ -76,19 +87,6 @@ bool qt_asyncify_resume()
return true;
}
-// Yields control to the browser, so that it can process events. Must
-// be called on the main thread. Returns false immediately if Qt has
-// already suspended the main thread. Returns true after yielding.
-bool qt_asyncify_yield()
-{
- if (g_is_asyncify_suspended)
- return false;
- emscripten_sleep(0);
- return true;
-}
-
-#endif // QT_HAVE_EMSCRIPTEN_ASYNCIFY
-
Q_CONSTINIT QEventDispatcherWasm *QEventDispatcherWasm::g_mainThreadEventDispatcher = nullptr;
#if QT_CONFIG(thread)
Q_CONSTINIT QVector<QEventDispatcherWasm *> QEventDispatcherWasm::g_secondaryThreadEventDispatchers;
@@ -198,9 +196,6 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags)
handleApplicationExec();
}
- if (!(flags & QEventLoop::ExcludeUserInputEvents))
- pollForNativeEvents();
-
hasPendingEvents = qGlobalPostedEventsCount() > 0;
if (!hasPendingEvents && (flags & QEventLoop::WaitForMoreEvents))
@@ -373,34 +368,14 @@ void QEventDispatcherWasm::handleApplicationExec()
void QEventDispatcherWasm::handleDialogExec()
{
-#ifndef QT_HAVE_EMSCRIPTEN_ASYNCIFY
- qWarning() << "Warning: dialog exec() is not supported on Qt for WebAssembly in this"
- << "configuration. Please use show() instead, or enable experimental support"
- << "for asyncify.\n"
- << "When using exec() (without asyncify) the dialog will show, the user can interact"
- << "with it and the appropriate signals will be emitted on close. However, the"
- << "exec() call never returns, stack content at the time of the exec() call"
- << "is leaked, and the exec() call may interfere with input event processing";
- emscripten_sleep(1); // This call never returns
-#endif
+ if (!qt_have_asyncify()) {
+ qWarning() << "Warning: exec() is not supported on Qt for WebAssembly in this configuration. Please build"
+ << "with asyncify support, or use an asynchronous API like QDialog::open()";
+ emscripten_sleep(1); // This call never returns
+ }
// For the asyncify case we do nothing here and wait for events in wait()
}
-void QEventDispatcherWasm::pollForNativeEvents()
-{
- // Secondary thread event dispatchers do not support native events
- if (isSecondaryThreadEventDispatcher())
- return;
-
-#if HAVE_EMSCRIPTEN_ASYNCIFY
- // Asyncify allows us to yield to the browser and have it process native events -
- // but this will fail if we are recursing and are already in a yield.
- bool didYield = qt_asyncify_yield();
- if (!didYield)
- qWarning("QEventDispatcherWasm::processEvents() did not asyncify process native events");
-#endif
-}
-
// Blocks/suspends the calling thread. This is possible in two cases:
// - Caller is a secondary thread: block on m_moreEvents
// - Caller is the main thread and asyncify is enabled: suspend using qt_asyncify_suspend()
@@ -422,20 +397,20 @@ bool QEventDispatcherWasm::wait(int timeout)
#endif
Q_ASSERT(emscripten_is_main_runtime_thread());
Q_ASSERT(isMainThreadEventDispatcher());
-#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
- if (timeout > 0)
- qWarning() << "QEventDispatcherWasm asyncify wait with timeout is not supported; timeout will be ignored"; // FIXME
-
- bool didSuspend = qt_asyncify_suspend();
- if (!didSuspend) {
- qWarning("QEventDispatcherWasm: current thread is already suspended; could not asyncify wait for events");
- return false;
+ if (qt_have_asyncify()) {
+ if (timeout > 0)
+ qWarning() << "QEventDispatcherWasm asyncify wait with timeout is not supported; timeout will be ignored"; // FIXME
+
+ bool didSuspend = qt_asyncify_suspend();
+ if (!didSuspend) {
+ qWarning("QEventDispatcherWasm: current thread is already suspended; could not asyncify wait for events");
+ return false;
+ }
+ return true;
+ } else {
+ qWarning("QEventLoop::WaitForMoreEvents is not supported on the main thread without asyncify");
+ Q_UNUSED(timeout);
}
- return true;
-#else
- qWarning("QEventLoop::WaitForMoreEvents is not supported on the main thread without asyncify");
- Q_UNUSED(timeout);
-#endif
return false;
}
@@ -453,12 +428,10 @@ bool QEventDispatcherWasm::wakeEventDispatcherThread()
}
#endif
Q_ASSERT(isMainThreadEventDispatcher());
-#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
if (g_is_asyncify_suspended) {
runOnMainThread([]{ qt_asyncify_resume(); });
return true;
}
-#endif
return false;
}
@@ -522,6 +495,7 @@ void QEventDispatcherWasm::updateNativeTimer()
if (m_timerId > 0) {
emscripten_clear_timeout(m_timerId);
m_timerId = 0;
+ m_timerTargetTime = 0;
}
return;
}
diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h
index a0cd182d82..b6de4187f4 100644
--- a/src/corelib/kernel/qeventdispatcher_wasm_p.h
+++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h
@@ -62,7 +62,6 @@ private:
void handleApplicationExec();
void handleDialogExec();
- void pollForNativeEvents();
bool wait(int timeout = -1);
bool wakeEventDispatcherThread();
static void callProcessEvents(void *eventDispatcher);
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index 04e1abf16a..1c54c97514 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -764,7 +764,7 @@ QEventDispatcherWin32::registeredTimers(QObject *object) const
Q_D(const QEventDispatcherWin32);
QList<TimerInfo> list;
- for (WinTimerInfo *t : qAsConst(d->timerDict)) {
+ for (WinTimerInfo *t : std::as_const(d->timerDict)) {
Q_ASSERT(t);
if (t->obj == object)
list << TimerInfo(t->timerId, t->interval, t->timerType);
@@ -832,7 +832,7 @@ void QEventDispatcherWin32::closingDown()
Q_ASSERT(d->active_fd.isEmpty());
// clean up any timers
- for (WinTimerInfo *t : qAsConst(d->timerDict))
+ for (WinTimerInfo *t : std::as_const(d->timerDict))
d->unregisterTimer(t);
d->timerDict.clear();
diff --git a/src/corelib/kernel/qjnihelpers.cpp b/src/corelib/kernel/qjnihelpers.cpp
index 94b280baac..c265b9facb 100644
--- a/src/corelib/kernel/qjnihelpers.cpp
+++ b/src/corelib/kernel/qjnihelpers.cpp
@@ -53,7 +53,7 @@ static jboolean dispatchGenericMotionEvent(JNIEnv *, jclass, jobject event)
{
jboolean ret = JNI_FALSE;
QMutexLocker locker(&g_genericMotionEventListeners()->mutex);
- for (auto *listener : qAsConst(g_genericMotionEventListeners()->listeners))
+ for (auto *listener : std::as_const(g_genericMotionEventListeners()->listeners))
ret |= listener->handleGenericMotionEvent(event);
return ret;
}
@@ -70,7 +70,7 @@ static jboolean dispatchKeyEvent(JNIEnv *, jclass, jobject event)
{
jboolean ret = JNI_FALSE;
QMutexLocker locker(&g_keyEventListeners()->mutex);
- for (auto *listener : qAsConst(g_keyEventListeners()->listeners))
+ for (auto *listener : std::as_const(g_keyEventListeners()->listeners))
ret |= listener->handleKeyEvent(event);
return ret;
}
diff --git a/src/corelib/kernel/qjniobject.cpp b/src/corelib/kernel/qjniobject.cpp
index 62a5993559..df4335092e 100644
--- a/src/corelib/kernel/qjniobject.cpp
+++ b/src/corelib/kernel/qjniobject.cpp
@@ -393,10 +393,15 @@ void QJniObject::callVoidMethodV(JNIEnv *env, jmethodID id, ...) const
{
va_list args;
va_start(args, id);
- env->CallVoidMethodV(d->m_jobject, id, args);
+ callVoidMethodV(env, id, args);
va_end(args);
}
+void QJniObject::callVoidMethodV(JNIEnv *env, jmethodID id, va_list args) const
+{
+ env->CallVoidMethodV(d->m_jobject, id, args);
+}
+
jmethodID QJniObject::getCachedMethodID(JNIEnv *env,
jclass clazz,
const QByteArray &className,
diff --git a/src/corelib/kernel/qjniobject.h b/src/corelib/kernel/qjniobject.h
index 2ae4c03dca..56dfdabf5e 100644
--- a/src/corelib/kernel/qjniobject.h
+++ b/src/corelib/kernel/qjniobject.h
@@ -434,6 +434,8 @@ private:
const char *signature, bool isStatic = false);
void callVoidMethodV(JNIEnv *env, jmethodID id, ...) const;
+ // ### Qt 7: merge into ... overload
+ void callVoidMethodV(JNIEnv *env, jmethodID id, va_list args) const;
QJniObject callObjectMethodV(const char *methodName, const char *signature,
va_list args) const;
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index c73fd425c2..fe8c25f1e5 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -227,7 +227,7 @@ QObject *QMetaObject::newInstance(QGenericArgument val0,
constructorName.remove(0, idx+1); // remove qualified part
}
QVarLengthArray<char, 512> sig;
- sig.append(constructorName.constData(), constructorName.length());
+ sig.append(constructorName.constData(), constructorName.size());
sig.append('(');
enum { MaximumParamCount = 10 };
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 3538d3cd47..38ffd95992 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -5,6 +5,7 @@
#include "qmetatype.h"
#include "qmetatype_p.h"
+#include "qobject.h"
#include "qobjectdefs.h"
#include "qdatetime.h"
#include "qbytearray.h"
@@ -400,7 +401,8 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
\omitvalue LastCoreType
\omitvalue LastGuiType
- Additional types can be registered using Q_DECLARE_METATYPE().
+ Additional types can be registered using qRegisterMetaType() or by calling
+ registerType().
\sa type(), typeName()
*/
@@ -438,17 +440,19 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
The class is used as a helper to marshall types in QVariant and
in queued signals and slots connections. It associates a type
name to a type so that it can be created and destructed
- dynamically at run-time. Declare new types with Q_DECLARE_METATYPE()
- to make them available to QVariant and other template-based functions.
- Call qRegisterMetaType() to make types available to non-template based
- functions, such as the queued signal and slot connections.
+ dynamically at run-time.
- Any class or struct that has a public default
- constructor, a public copy constructor, and a public destructor
- can be registered.
+ Type names can be registered with QMetaType by using either
+ qRegisterMetaType() or registerType(). Registration is not required for
+ most operations; it's only required for operations that attempt to resolve
+ a type name in string form back to a QMetaType object or the type's ID.
+ Those include some old-style signal-slot connections using
+ QObject::connect(), reading user-types from \l QDataStream to \l QVariant,
+ or binding to other languages and IPC mechanisms, like QML, D-Bus,
+ JavaScript, etc.
- The following code allocates and destructs an instance of
- \c{MyClass}:
+ The following code allocates and destructs an instance of \c{MyClass} by
+ its name, which requires that \c{MyClass} have been previously registered:
\snippet code/src_corelib_kernel_qmetatype.cpp 3
@@ -552,19 +556,21 @@ int QMetaType::idHelper() const
\fn constexpr const QMetaObject *QMetaType::metaObject() const
\since 5.5
- return a QMetaObject relative to this type.
+ Returns a QMetaObject relative to this type.
If the type is a pointer type to a subclass of QObject, flags() contains
- QMetaType::PointerToQObject and this function returns the corresponding QMetaObject. This can
- be used to in combinaison with QMetaObject::construct to create QObject of this type.
+ QMetaType::PointerToQObject and this function returns the corresponding QMetaObject.
+ This can be used in combination with QMetaObject::newInstance() to create QObjects of this type.
- If the type is a Q_GADGET, flags() contains QMetaType::IsGadget, and this function returns its
- QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a
- pointer of this type. (given by QVariant::data for example)
+ If the type is a Q_GADGET, flags() contains QMetaType::IsGadget.
+ If the type is a pointer to a Q_GADGET, flags() contains QMetaType::PointerToGadget.
+ In both cases, this function returns its QMetaObject.
+ This can be used to retrieve QMetaMethod and QMetaProperty and use them on a
+ pointer of this type for example, as given by QVariant::data().
- If the type is an enumeration, flags() contains QMetaType::IsEnumeration, and this function
- returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or
- \nullptr otherwise
+ If the type is an enumeration, flags() contains QMetaType::IsEnumeration.
+ In this case, this function returns the QMetaObject of the enclosing
+ object if the enum was registered as a Q_ENUM or \nullptr otherwise.
\sa QMetaType::flags()
*/
@@ -1084,7 +1090,7 @@ static const struct : QMetaTypeModuleHelper
#endif
QMETATYPE_CONVERTER(QString, QByteArray, result = QString::fromUtf8(source); return true;);
QMETATYPE_CONVERTER(QString, QStringList,
- return (source.count() == 1) ? (result = source.at(0), true) : false;
+ return (source.size() == 1) ? (result = source.at(0), true) : false;
);
#ifndef QT_BOOTSTRAPPED
QMETATYPE_CONVERTER(QString, QUrl, result = source.toString(); return true;);
@@ -1766,10 +1772,16 @@ static QMetaEnum metaEnumFromType(QMetaType t)
{
if (t.flags() & QMetaType::IsEnumeration) {
if (const QMetaObject *metaObject = t.metaObject()) {
- const QByteArray enumName = t.name();
- const char *lastColon = std::strrchr(enumName, ':');
- return metaObject->enumerator(metaObject->indexOfEnumerator(
- lastColon ? lastColon + 1 : enumName.constData()));
+ QByteArrayView qflagsNamePrefix = "QFlags<";
+ QByteArray enumName = t.name();
+ if (enumName.endsWith('>') && enumName.startsWith(qflagsNamePrefix)) {
+ // extract the template argument
+ enumName.chop(1);
+ enumName = enumName.sliced(qflagsNamePrefix.size());
+ }
+ if (qsizetype lastColon = enumName.lastIndexOf(':'); lastColon != -1)
+ enumName = enumName.sliced(lastColon + 1);
+ return metaObject->enumerator(metaObject->indexOfEnumerator(enumName));
}
}
return QMetaEnum();
@@ -1832,11 +1844,19 @@ static bool convertFromEnum(QMetaType fromType, const void *from, QMetaType toTy
#ifndef QT_NO_QOBJECT
QMetaEnum en = metaEnumFromType(fromType);
if (en.isValid()) {
- const char *key = en.valueToKey(ll);
- if (toType.id() == QMetaType::QString)
- *static_cast<QString *>(to) = QString::fromUtf8(key);
- else
- *static_cast<QByteArray *>(to) = key;
+ if (en.isFlag()) {
+ const QByteArray keys = en.valueToKeys(ll);
+ if (toType.id() == QMetaType::QString)
+ *static_cast<QString *>(to) = QString::fromUtf8(keys);
+ else
+ *static_cast<QByteArray *>(to) = keys;
+ } else {
+ const char *key = en.valueToKey(ll);
+ if (toType.id() == QMetaType::QString)
+ *static_cast<QString *>(to) = QString::fromUtf8(key);
+ else
+ *static_cast<QByteArray *>(to) = key;
+ }
return true;
}
#endif
@@ -2419,7 +2439,7 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType)
return true;
}
const ConverterFunction * const f =
- customTypesConversionRegistry()->function(qMakePair(fromTypeId, toTypeId));
+ customTypesConversionRegistry()->function(std::make_pair(fromTypeId, toTypeId));
if (f)
return true;
@@ -2673,9 +2693,6 @@ Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *typeName)
Returns \c true if the object is saved successfully; otherwise
returns \c false.
- The type must have been registered with Q_DECLARE_METATYPE()
- beforehand.
-
Normally, you should not need to call this function directly.
Instead, use QVariant's \c operator<<(), which relies on save()
to stream custom types.
@@ -2714,9 +2731,6 @@ bool QMetaType::save(QDataStream &stream, const void *data) const
Returns \c true if the object is loaded successfully; otherwise
returns \c false.
- The type must have been registered with Q_DECLARE_METATYPE()
- beforehand.
-
Normally, you should not need to call this function directly.
Instead, use QVariant's \c operator>>(), which relies on load()
to stream custom types.
@@ -2971,6 +2985,13 @@ static const QtPrivate::QMetaTypeInterface *interfaceForType(int typeId)
}
/*!
+ \fn QMetaType::QMetaType()
+ \since 6.0
+
+ Constructs a default, invalid, QMetaType object.
+*/
+
+/*!
\fn QMetaType::QMetaType(int typeId)
\since 5.0
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index cdad83a467..f015daebe5 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -1127,7 +1127,12 @@ template <typename T>
struct QMetaTypeId2<const T&> : QMetaTypeId2<T> {};
template <typename T>
-struct QMetaTypeId2<T&> { enum {Defined = false }; };
+struct QMetaTypeId2<T&>
+{
+ using NameAsArrayType = void;
+ enum { Defined = false, IsBuiltIn = false };
+ static inline constexpr int qt_metatype_id() { return 0; }
+};
namespace QtPrivate {
template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
@@ -2268,6 +2273,20 @@ struct QDataStreamOperatorForType <T, false>
static constexpr QMetaTypeInterface::DataStreamInFn dataStreamIn = nullptr;
};
+// Performance optimization:
+//
+// Don't add all these symbols to the dynamic symbol tables on ELF systems and
+// on Darwin. Each library is going to have a copy anyway and QMetaType already
+// copes with some of these being "hidden" (see QMetaType::idHelper()). We may
+// as well let the linker know it can always use the local copy.
+//
+// This is currently not enabled for GCC due to
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106023
+
+#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
+# pragma GCC visibility push(hidden)
+#endif
+
template<typename S>
class QMetaTypeForType
{
@@ -2358,6 +2377,9 @@ struct QMetaTypeInterfaceWrapper
};
};
+#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
+# pragma GCC visibility pop
+#endif
template<>
class QMetaTypeInterfaceWrapper<void>
@@ -2495,7 +2517,14 @@ constexpr const QMetaObject *QMetaType::metaObject() const
template<typename... T>
constexpr const QtPrivate::QMetaTypeInterface *const qt_metaTypeArray[] = {
- QtPrivate::qMetaTypeInterfaceForType<T>()...
+ /*
+ Unique in qTryMetaTypeInterfaceForType does not have to be unique here
+ as we require _all_ types here to be actually complete.
+ We just want to have the additional type processing that exist in
+ QtPrivate::qTryMetaTypeInterfaceForType as opposed to the normal
+ QtPrivate::qMetaTypeInterfaceForType used in QMetaType::fromType
+ */
+ QtPrivate::qTryMetaTypeInterfaceForType<void, QtPrivate::TypeAndForceComplete<T, std::true_type>>()...
};
constexpr const char *QMetaType::name() const
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index a7f48b5c59..35e503d330 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1001,7 +1001,7 @@ QObject::~QObject()
emit destroyed(this);
}
- if (d->declarativeData && QAbstractDeclarativeData::destroyed)
+ if (!d->isDeletingChildren && d->declarativeData && QAbstractDeclarativeData::destroyed)
QAbstractDeclarativeData::destroyed(d->declarativeData, this);
QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
@@ -2155,7 +2155,7 @@ void QObjectPrivate::deleteChildren()
// delete children objects
// don't use qDeleteAll as the destructor of the child might
// delete siblings
- for (int i = 0; i < children.count(); ++i) {
+ for (int i = 0; i < children.size(); ++i) {
currentChildBeingDeleted = children.at(i);
children[i] = nullptr;
delete currentChildBeingDeleted;
@@ -2303,7 +2303,7 @@ void QObject::removeEventFilter(QObject *obj)
{
Q_D(QObject);
if (d->extraData) {
- for (int i = 0; i < d->extraData->eventFilters.count(); ++i) {
+ for (int i = 0; i < d->extraData->eventFilters.size(); ++i) {
if (d->extraData->eventFilters.at(i) == obj)
d->extraData->eventFilters[i] = nullptr;
}
@@ -2625,7 +2625,7 @@ int QObject::receivers(const char *signal) const
if (!d->isSignalConnected(signal_index))
return receivers;
- if (d->declarativeData && QAbstractDeclarativeData::receivers) {
+ if (!d->isDeletingChildren && d->declarativeData && QAbstractDeclarativeData::receivers) {
receivers += QAbstractDeclarativeData::receivers(d->declarativeData, this,
signal_index);
}
@@ -2653,13 +2653,15 @@ int QObject::receivers(const char *signal) const
\snippet code/src_corelib_kernel_qobject.cpp 49
- As the code snippet above illustrates, you can use this function
- to avoid emitting a signal that nobody listens to.
+ As the code snippet above illustrates, you can use this function to avoid
+ expensive initialization or emitting a signal that nobody listens to.
+ However, in a multithreaded application, connections might change after
+ this function returns and before the signal gets emitted.
\warning This function violates the object-oriented principle of
- modularity. However, it might be useful when you need to perform
- expensive initialization only if something is connected to a
- signal.
+ modularity. In particular, this function must not be called from an
+ override of connectNotify() or disconnectNotify(), as those might get
+ called from any thread.
*/
bool QObject::isSignalConnected(const QMetaMethod &signal) const
{
@@ -3333,8 +3335,13 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
signal.
\warning This function is called from the thread which performs the
- connection, which may be a different thread from the thread in
- which this object lives.
+ connection, which may be a different thread from the thread in which
+ this object lives. This function may also be called with a QObject internal
+ mutex locked. It is therefore not allowed to re-enter any QObject
+ functions, including isSignalConnected(), from your reimplementation. If
+ you lock a mutex in your reimplementation, make sure that you don't call
+ QObject functions with that mutex held in other places or it will result in
+ a deadlock.
\sa connect(), disconnectNotify()
*/
@@ -3363,12 +3370,12 @@ void QObject::connectNotify(const QMetaMethod &signal)
expensive resources.
\warning This function is called from the thread which performs the
- disconnection, which may be a different thread from the thread in
- which this object lives. This function may also be called with a QObject
- internal mutex locked. It is therefore not allowed to re-enter any
- of any QObject functions from your reimplementation and if you lock
- a mutex in your reimplementation, make sure that you don't call QObject
- functions with that mutex held in other places or it will result in
+ disconnection, which may be a different thread from the thread in which
+ this object lives. This function may also be called with a QObject internal
+ mutex locked. It is therefore not allowed to re-enter any QObject
+ functions, including isSignalConnected(), from your reimplementation. If
+ you lock a mutex in your reimplementation, make sure that you don't call
+ QObject functions with that mutex held in other places or it will result in
a deadlock.
\sa disconnect(), connectNotify()
@@ -3684,7 +3691,7 @@ void QMetaObject::connectSlotsByName(QObject *o)
// ...we check each object in our list, ...
bool foundIt = false;
- for (int j = 0; j < list.count(); ++j) {
+ for (int j = 0; j < list.size(); ++j) {
const QObject *co = list.at(j);
const QByteArray coName = co->objectName().toLatin1();
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 7fa2790208..358f151495 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -20,9 +20,7 @@
#include <QtCore/qobject_impl.h>
#include <QtCore/qbindingstorage.h>
-#if __has_include(<chrono>)
-# include <chrono>
-#endif
+#include <chrono>
QT_BEGIN_NAMESPACE
@@ -128,13 +126,11 @@ public:
void moveToThread(QThread *thread);
int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer);
-#if __has_include(<chrono>)
Q_ALWAYS_INLINE
int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer)
{
return startTimer(int(time.count()), timerType);
}
-#endif
void killTimer(int id);
template<typename T>
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 3f55fba6b0..f82dce51f3 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -225,7 +225,7 @@ inline void QObjectPrivate::checkForIncompatibleLibraryVersion(int version) cons
inline bool QObjectPrivate::isDeclarativeSignalConnected(uint signal_index) const
{
- return declarativeData && QAbstractDeclarativeData::isSignalConnected
+ return !isDeletingChildren && declarativeData && QAbstractDeclarativeData::isSignalConnected
&& QAbstractDeclarativeData::isSignalConnected(declarativeData, q_func(), signal_index);
}
diff --git a/src/corelib/kernel/qpoll.cpp b/src/corelib/kernel/qpoll.cpp
index eba5664f4a..bbd197f292 100644
--- a/src/corelib/kernel/qpoll.cpp
+++ b/src/corelib/kernel/qpoll.cpp
@@ -156,6 +156,11 @@ int qt_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts)
if (fds[i].fd < 0)
continue;
+ if (fds[i].fd > FD_SETSIZE) {
+ errno = EINVAL;
+ return -1;
+ }
+
if (fds[i].events & QT_POLL_EVENTS_MASK)
continue;
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index 22422995fe..a94e3ad989 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -118,7 +118,7 @@ struct QPropertyDelayedNotifications
Change notifications are sent later with notify (following the logic of separating
binding updates and notifications used in non-deferred updates).
*/
- void evaluateBindings(int index, QBindingStatus *status) {
+ void evaluateBindings(PendingBindingObserverList &bindingObservers, qsizetype index, QBindingStatus *status) {
auto *delayed = delayedProperties + index;
auto *bindingData = delayed->originalBindingData;
if (!bindingData)
@@ -134,7 +134,7 @@ struct QPropertyDelayedNotifications
QPropertyBindingDataPointer bindingDataPointer{bindingData};
QPropertyObserverPointer observer = bindingDataPointer.firstObserver();
if (observer)
- observer.evaluateBindings(status);
+ observer.evaluateBindings(bindingObservers, status);
}
/*!
@@ -146,19 +146,19 @@ struct QPropertyDelayedNotifications
\li sends any pending notifications.
\endlist
*/
- void notify(int index) {
+ void notify(qsizetype index) {
auto *delayed = delayedProperties + index;
- auto *bindingData = delayed->originalBindingData;
- if (!bindingData)
+ if (delayed->d_ptr & QPropertyBindingData::BindingBit)
+ return; // already handled
+ if (!delayed->originalBindingData)
return;
-
delayed->originalBindingData = nullptr;
+
+ QPropertyObserverPointer observer { reinterpret_cast<QPropertyObserver *>(delayed->d_ptr & ~QPropertyBindingData::DelayedNotificationBit) };
delayed->d_ptr = 0;
- QPropertyBindingDataPointer bindingDataPointer{bindingData};
- QPropertyObserverPointer observer = bindingDataPointer.firstObserver();
if (observer)
- observer.notify(delayed->propertyData);
+ observer.notify<QPropertyObserverPointer::Notify::OnlyChangeHandlers>(delayed->propertyData);
}
};
@@ -213,17 +213,24 @@ void Qt::endPropertyUpdateGroup()
if (--data->ref)
return;
groupUpdateData = nullptr;
+ // ensures that bindings are kept alive until endPropertyUpdateGroup concludes
+ PendingBindingObserverList bindingObservers;
// update all delayed properties
auto start = data;
while (data) {
- for (int i = 0; i < data->used; ++i)
- data->evaluateBindings(i, status);
+ for (qsizetype i = 0; i < data->used; ++i)
+ data->evaluateBindings(bindingObservers, i, status);
data = data->next;
}
- // notify all delayed properties
+ // notify all delayed notifications from binding evaluation
+ for (const QBindingObserverPtr &observer: bindingObservers) {
+ QPropertyBindingPrivate *binding = observer.binding();
+ binding->notifyNonRecursive();
+ }
+ // do the same for properties which only have observers
data = start;
while (data) {
- for (int i = 0; i < data->used; ++i)
+ for (qsizetype i = 0; i < data->used; ++i)
data->notify(i);
auto *next = data->next;
delete data;
@@ -271,11 +278,11 @@ void QPropertyBindingPrivate::unlinkAndDeref()
destroyAndFreeMemory(this);
}
-void QPropertyBindingPrivate::evaluateRecursive(QBindingStatus *status)
+void QPropertyBindingPrivate::evaluateRecursive(PendingBindingObserverList &bindingObservers, QBindingStatus *status)
{
if (!status)
status = &bindingStatus;
- return evaluateRecursive_inline(status);
+ return evaluateRecursive_inline(bindingObservers, status);
}
void QPropertyBindingPrivate::notifyRecursive()
@@ -294,6 +301,31 @@ void QPropertyBindingPrivate::notifyRecursive()
updating = false;
}
+void QPropertyBindingPrivate::notifyNonRecursive(const PendingBindingObserverList &bindingObservers)
+{
+ notifyNonRecursive();
+ for (auto &&bindingObserver: bindingObservers) {
+ bindingObserver.binding()->notifyNonRecursive();
+ }
+}
+
+QPropertyBindingPrivate::NotificationState QPropertyBindingPrivate::notifyNonRecursive()
+{
+ if (!pendingNotify)
+ return Delayed;
+ pendingNotify = false;
+ Q_ASSERT(!updating);
+ updating = true;
+ if (firstObserver) {
+ firstObserver.noSelfDependencies(this);
+ firstObserver.notifyOnlyChangeHandler(propertyDataPtr);
+ }
+ if (hasStaticObserver)
+ staticObserverCallback(propertyDataPtr);
+ updating = false;
+ return Sent;
+}
+
/*!
Constructs a null QUntypedPropertyBinding.
@@ -415,6 +447,8 @@ QMetaType QUntypedPropertyBinding::valueMetaType() const
QPropertyBindingData::~QPropertyBindingData()
{
QPropertyBindingDataPointer d{this};
+ if (isNotificationDelayed())
+ proxyData()->originalBindingData = nullptr;
for (auto observer = d.firstObserver(); observer;) {
auto next = observer.nextObserver();
observer.unlink();
@@ -461,8 +495,9 @@ QUntypedPropertyBinding QPropertyBindingData::setBinding(const QUntypedPropertyB
newBindingRaw->prependObserver(observer);
newBindingRaw->setStaticObserver(staticObserverCallback, guardCallback);
- newBindingRaw->evaluateRecursive();
- newBindingRaw->notifyRecursive();
+ PendingBindingObserverList bindingObservers;
+ newBindingRaw->evaluateRecursive(bindingObservers);
+ newBindingRaw->notifyNonRecursive(bindingObservers);
} else if (observer) {
d.setObservers(observer.ptr);
} else {
@@ -565,18 +600,31 @@ void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr
return;
QPropertyBindingDataPointer d{this};
+ PendingBindingObserverList bindingObservers;
if (QPropertyObserverPointer observer = d.firstObserver()) {
- if (notifyObserver_helper(propertyDataPtr, observer, storage) == Evaluated) {
- // evaluateBindings() can trash the observers. We need to re-fetch here.
+ if (notifyObserver_helper(propertyDataPtr, storage, observer, bindingObservers) == Evaluated) {
+ /* evaluateBindings() can trash the observers. We need to re-fetch here.
+ "this" might also no longer be valid in case we have a QObjectBindableProperty
+ and consequently d isn't either (this happens when binding evaluation has
+ caused the binding storage to resize.
+ If storage is nullptr, then there is no dynamically resizable storage,
+ and we cannot run into the issue.
+ */
+ if (storage)
+ d = QPropertyBindingDataPointer {storage->bindingData(propertyDataPtr)};
if (QPropertyObserverPointer observer = d.firstObserver())
- observer.notify(propertyDataPtr);
+ observer.notifyOnlyChangeHandler(propertyDataPtr);
+ for (auto &&bindingObserver: bindingObservers)
+ bindingObserver.binding()->notifyNonRecursive();
}
}
}
-QPropertyBindingData::NotificationResult QPropertyBindingData::notifyObserver_helper(
- QUntypedPropertyData *propertyDataPtr, QPropertyObserverPointer observer,
- QBindingStorage *storage) const
+QPropertyBindingData::NotificationResult QPropertyBindingData::notifyObserver_helper
+(
+ QUntypedPropertyData *propertyDataPtr, QBindingStorage *storage,
+ QPropertyObserverPointer observer,
+ PendingBindingObserverList &bindingObservers) const
{
#ifdef QT_HAS_FAST_CURRENT_THREAD_ID
QBindingStatus *status = storage ? storage->bindingStatus : nullptr;
@@ -591,7 +639,7 @@ QPropertyBindingData::NotificationResult QPropertyBindingData::notifyObserver_he
return Delayed;
}
- observer.evaluateBindings(status);
+ observer.evaluateBindings(bindingObservers, status);
return Evaluated;
}
@@ -724,7 +772,7 @@ void QPropertyObserverPointer::noSelfDependencies(QPropertyBindingPrivate *bindi
}
#endif
-void QPropertyObserverPointer::evaluateBindings(QBindingStatus *status)
+void QPropertyObserverPointer::evaluateBindings(PendingBindingObserverList &bindingObservers, QBindingStatus *status)
{
Q_ASSERT(status);
auto observer = const_cast<QPropertyObserver*>(ptr);
@@ -733,9 +781,10 @@ void QPropertyObserverPointer::evaluateBindings(QBindingStatus *status)
QPropertyObserver *next = observer->next.data();
if (QPropertyObserver::ObserverTag(observer->next.tag()) == QPropertyObserver::ObserverNotifiesBinding) {
+ bindingObservers.push_back(observer);
auto bindingToEvaluate = observer->binding;
QPropertyObserverNodeProtector protector(observer);
- bindingToEvaluate->evaluateRecursive_inline(status);
+ bindingToEvaluate->evaluateRecursive_inline(bindingObservers, status);
next = protector.next();
}
@@ -1565,13 +1614,13 @@ QString QPropertyBindingError::description() const
have changed. Whenever a bindable property used in the callback changes,
this happens automatically. If the result of the callback might change
because of a change in a value which is not a bindable property,
- it is the developer's responsibility to call markDirty
+ it is the developer's responsibility to call \c notify
on the QObjectComputedProperty object.
This will inform dependent properties about the potential change.
- Note that calling markDirty might trigger change handlers in dependent
+ Note that calling \c notify might trigger change handlers in dependent
properties, which might in turn use the object the QObjectComputedProperty
- is a member of. So markDirty must not be called when in a transitional
+ is a member of. So \c notify must not be called when in a transitional
or invalid state.
QObjectComputedProperty is not suitable for use with a computation that depends
diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h
index fbd838654f..4968b29cee 100644
--- a/src/corelib/kernel/qproperty.h
+++ b/src/corelib/kernel/qproperty.h
@@ -18,7 +18,16 @@
#if defined(__cpp_lib_source_location)
#define QT_SOURCE_LOCATION_NAMESPACE std
#define QT_PROPERTY_COLLECT_BINDING_LOCATION
-#define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::source_location::current())
+#if defined(Q_CC_MSVC)
+/* MSVC runs into an issue with constexpr with source location (error C7595)
+ so use the factory function as a workaround */
+# define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation::fromStdSourceLocation(std::source_location::current())
+#else
+/* some versions of gcc in turn run into
+ expression ‘std::source_location::current()’ is not a constant expression
+ so don't use the workaround there */
+# define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::source_location::current())
+#endif
#endif
#endif
@@ -86,6 +95,12 @@ struct Q_CORE_EXPORT QPropertyBindingSourceLocation
line = cppLocation.line();
column = cppLocation.column();
}
+ QT_POST_CXX17_API_IN_EXPORTED_CLASS
+ static consteval QPropertyBindingSourceLocation
+ fromStdSourceLocation(const std::source_location &cppLocation)
+ {
+ return cppLocation;
+ }
#endif
#ifdef __cpp_lib_experimental_source_location
constexpr QPropertyBindingSourceLocation(const std::experimental::source_location &cppLocation)
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index a569c172c5..8e747b4f64 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -21,6 +21,7 @@
#include <qscopedpointer.h>
#include <qscopedvaluerollback.h>
#include <vector>
+#include <QtCore/QVarLengthArray>
QT_BEGIN_NAMESPACE
@@ -29,6 +30,34 @@ namespace QtPrivate {
struct QBindingStatusAccessToken {};
}
+
+/*!
+ \internal
+ Similar to \c QPropertyBindingPrivatePtr, but stores a
+ \c QPropertyObserver * linking to the QPropertyBindingPrivate*
+ instead of the QPropertyBindingPrivate* itself
+ */
+struct QBindingObserverPtr
+{
+private:
+ QPropertyObserver *d = nullptr;
+public:
+ QBindingObserverPtr() = default;
+ Q_DISABLE_COPY(QBindingObserverPtr);
+ void swap(QBindingObserverPtr &other) noexcept
+ { qt_ptr_swap(d, other.d); }
+ QBindingObserverPtr(QBindingObserverPtr &&other) : d(std::exchange(other.d, nullptr)) {}
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QBindingObserverPtr);
+
+
+ inline QBindingObserverPtr(QPropertyObserver *observer);
+ inline ~QBindingObserverPtr();
+ inline QPropertyBindingPrivate *binding() const;
+ inline QPropertyObserver *operator ->();
+};
+
+using PendingBindingObserverList = QVarLengthArray<QBindingObserverPtr>;
+
// Keep all classes related to QProperty in one compilation unit. Performance of this code is crucial and
// we need to allow the compiler to inline where it makes sense.
@@ -52,6 +81,7 @@ struct QPropertyBindingDataPointer
void Q_ALWAYS_INLINE addObserver(QPropertyObserver *observer);
inline void setFirstObserver(QPropertyObserver *observer);
inline QPropertyObserverPointer firstObserver() const;
+ static QPropertyProxyBindingData *proxyData(QtPrivate::QPropertyBindingData *ptr);
inline int observerCount() const;
@@ -106,19 +136,29 @@ struct QPropertyObserverPointer
void setBindingToNotify_unsafe(QPropertyBindingPrivate *binding);
void setChangeHandler(QPropertyObserver::ChangeHandler changeHandler);
+ enum class Notify {Everything, OnlyChangeHandlers};
+
+ template<Notify notifyPolicy = Notify::Everything>
void notify(QUntypedPropertyData *propertyDataPtr);
+ void notifyOnlyChangeHandler(QUntypedPropertyData *propertyDataPtr);
#ifndef QT_NO_DEBUG
void noSelfDependencies(QPropertyBindingPrivate *binding);
#else
void noSelfDependencies(QPropertyBindingPrivate *) {}
#endif
- void evaluateBindings(QBindingStatus *status);
+ void evaluateBindings(PendingBindingObserverList &bindingObservers, QBindingStatus *status);
void observeProperty(QPropertyBindingDataPointer property);
explicit operator bool() const { return ptr != nullptr; }
QPropertyObserverPointer nextObserver() const { return {ptr->next.data()}; }
+ QPropertyBindingPrivate *binding() const
+ {
+ Q_ASSERT(ptr->next.tag() == QPropertyObserver::ObserverNotifiesBinding);
+ return ptr->binding;
+ };
+
private:
void unlink_common()
{
@@ -321,10 +361,21 @@ public:
void unlinkAndDeref();
- void evaluateRecursive(QBindingStatus *status = nullptr);
- void Q_ALWAYS_INLINE evaluateRecursive_inline(QBindingStatus *status);
+ void evaluateRecursive(PendingBindingObserverList &bindingObservers, QBindingStatus *status = nullptr);
+
+ // ### TODO: remove as soon as declarative no longer needs this overload
+ void evaluateRecursive()
+ {
+ PendingBindingObserverList bindingObservers;
+ evaluateRecursive(bindingObservers);
+ }
+
+ void Q_ALWAYS_INLINE evaluateRecursive_inline(PendingBindingObserverList &bindingObservers, QBindingStatus *status);
void notifyRecursive();
+ void notifyNonRecursive(const PendingBindingObserverList &bindingObservers);
+ enum NotificationState : bool { Delayed, Sent };
+ NotificationState notifyNonRecursive();
static QPropertyBindingPrivate *get(const QUntypedPropertyBinding &binding)
{ return static_cast<QPropertyBindingPrivate *>(binding.d.data()); }
@@ -373,9 +424,9 @@ inline void QPropertyBindingDataPointer::fixupAfterMove(QtPrivate::QPropertyBind
{
auto &d = ptr->d_ref();
if (ptr->isNotificationDelayed()) {
- QPropertyProxyBindingData *proxyData
- = reinterpret_cast<QPropertyProxyBindingData*>(d & ~QtPrivate::QPropertyBindingData::BindingBit);
- proxyData->originalBindingData = ptr;
+ QPropertyProxyBindingData *proxy = ptr->proxyData();
+ Q_ASSERT(proxy);
+ proxy->originalBindingData = ptr;
}
// If QPropertyBindingData has been moved, and it has an observer
// we have to adjust the firstObserver's prev pointer to point to
@@ -393,6 +444,17 @@ inline QPropertyObserverPointer QPropertyBindingDataPointer::firstObserver() con
return { reinterpret_cast<QPropertyObserver *>(ptr->d()) };
}
+/*!
+ \internal
+ Returns the proxy data of \a ptr, or \c nullptr if \a ptr has no delayed notification
+ */
+inline QPropertyProxyBindingData *QPropertyBindingDataPointer::proxyData(QtPrivate::QPropertyBindingData *ptr)
+{
+ if (!ptr->isNotificationDelayed())
+ return nullptr;
+ return ptr->proxyData();
+}
+
inline int QPropertyBindingDataPointer::observerCount() const
{
int count = 0;
@@ -566,11 +628,14 @@ public:
QPropertyBindingDataPointer d{bd};
if (QPropertyObserverPointer observer = d.firstObserver()) {
if (!inBindingWrapper(storage)) {
- if (bd->notifyObserver_helper(this, observer, storage)
+ PendingBindingObserverList bindingObservers;
+ if (bd->notifyObserver_helper(this, storage, observer, bindingObservers)
== QtPrivate::QPropertyBindingData::Evaluated) {
// evaluateBindings() can trash the observers. We need to re-fetch here.
if (QPropertyObserverPointer observer = d.firstObserver())
- observer.notify(this);
+ observer.notifyOnlyChangeHandler(this);
+ for (auto&& bindingObserver: bindingObservers)
+ bindingObserver.binding()->notifyNonRecursive();
}
}
}
@@ -727,7 +792,7 @@ struct QUntypedBindablePrivate
}
};
-inline void QPropertyBindingPrivate::evaluateRecursive_inline(QBindingStatus *status)
+inline void QPropertyBindingPrivate::evaluateRecursive_inline(PendingBindingObserverList &bindingObservers, QBindingStatus *status)
{
if (updating) {
error = QPropertyBindingError(QPropertyBindingError::BindingLoop);
@@ -766,9 +831,10 @@ inline void QPropertyBindingPrivate::evaluateRecursive_inline(QBindingStatus *st
return;
firstObserver.noSelfDependencies(this);
- firstObserver.evaluateBindings(status);
+ firstObserver.evaluateBindings(bindingObservers, status);
}
+template<QPropertyObserverPointer::Notify notifyPolicy>
inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataPtr)
{
auto observer = const_cast<QPropertyObserver*>(ptr);
@@ -808,10 +874,12 @@ inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataP
}
case QPropertyObserver::ObserverNotifiesBinding:
{
- auto bindingToNotify = observer->binding;
- QPropertyObserverNodeProtector protector(observer);
- bindingToNotify->notifyRecursive();
- next = protector.next();
+ if constexpr (notifyPolicy == Notify::Everything) {
+ auto bindingToNotify = observer->binding;
+ QPropertyObserverNodeProtector protector(observer);
+ bindingToNotify->notifyRecursive();
+ next = protector.next();
+ }
break;
}
case QPropertyObserver::ObserverIsPlaceholder:
@@ -825,12 +893,29 @@ inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataP
}
}
+inline void QPropertyObserverPointer::notifyOnlyChangeHandler(QUntypedPropertyData *propertyDataPtr)
+{
+ notify<Notify::OnlyChangeHandlers>(propertyDataPtr);
+}
+
inline QPropertyObserverNodeProtector::~QPropertyObserverNodeProtector()
{
QPropertyObserverPointer d{static_cast<QPropertyObserver *>(&m_placeHolder)};
d.unlink_fast();
}
+QBindingObserverPtr::QBindingObserverPtr(QPropertyObserver *observer) : d(observer)
+{
+ Q_ASSERT(d);
+ QPropertyObserverPointer{d}.binding()->addRef();
+}
+
+QBindingObserverPtr::~QBindingObserverPtr() { if (d) QPropertyObserverPointer{d}.binding()->deref(); }
+
+QPropertyBindingPrivate *QBindingObserverPtr::binding() const { return QPropertyObserverPointer{d}.binding(); }
+
+QPropertyObserver *QBindingObserverPtr::operator->() { return d; }
+
QT_END_NAMESPACE
#endif // QPROPERTY_P_H
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h
index ab69e966cf..aec10e1994 100644
--- a/src/corelib/kernel/qpropertyprivate.h
+++ b/src/corelib/kernel/qpropertyprivate.h
@@ -18,6 +18,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qtaggedpointer.h>
#include <QtCore/qmetatype.h>
+#include <QtCore/qcontainerfwd.h>
#include <functional>
@@ -28,6 +29,9 @@ class QBindingStorage;
template<typename Class, typename T, auto Offset, auto Setter, auto Signal, auto Getter>
class QObjectCompatProperty;
+struct QBindingObserverPtr;
+using PendingBindingObserverList = QVarLengthArray<QBindingObserverPtr>;
+
namespace QtPrivate {
// QPropertyBindingPrivatePtr operates on a RefCountingMixin solely so that we can inline
// the constructor and copy constructor
@@ -115,6 +119,7 @@ private:
class QUntypedPropertyBinding;
class QPropertyBindingPrivate;
struct QPropertyBindingDataPointer;
+class QPropertyObserver;
struct QPropertyObserverPointer;
class QUntypedPropertyData
@@ -299,17 +304,23 @@ private:
{
quintptr &d = d_ptr;
if (isNotificationDelayed())
- return reinterpret_cast<QPropertyProxyBindingData *>(d_ptr & ~(BindingBit|DelayedNotificationBit))->d_ptr;
+ return proxyData()->d_ptr;
return d;
}
quintptr d() const { return d_ref(); }
+ QPropertyProxyBindingData *proxyData() const
+ {
+ Q_ASSERT(isNotificationDelayed());
+ return reinterpret_cast<QPropertyProxyBindingData *>(d_ptr & ~(BindingBit|DelayedNotificationBit));
+ }
void registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentBinding) const;
void removeBinding_helper();
enum NotificationResult { Delayed, Evaluated };
NotificationResult notifyObserver_helper(
- QUntypedPropertyData *propertyDataPtr, QPropertyObserverPointer observer,
- QBindingStorage *storage) const;
+ QUntypedPropertyData *propertyDataPtr, QBindingStorage *storage,
+ QPropertyObserverPointer observer,
+ PendingBindingObserverList &bindingObservers) const;
};
template <typename T, typename Tag>
diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp
index a789a58b65..28a9742c69 100644
--- a/src/corelib/kernel/qsharedmemory.cpp
+++ b/src/corelib/kernel/qsharedmemory.cpp
@@ -144,6 +144,12 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,
\endlist
+ Qt for iOS comes with support for POSIX shared memory out of the box.
+ With Qt for \macos an additional configure flag must be added when
+ building Qt to enable the feature. To enable the feature pass
+ \c {-feature-ipc_posix} Note that the pre-built Qt libraries for
+ \macos available through the Qt installer do not include this feature.
+
\endlist
Remember to lock the shared memory with lock() before reading from
diff --git a/src/corelib/kernel/qt_attribution.json b/src/corelib/kernel/qt_attribution.json
index 6d8f4f2abc..c3075c0a52 100644
--- a/src/corelib/kernel/qt_attribution.json
+++ b/src/corelib/kernel/qt_attribution.json
@@ -3,7 +3,7 @@
"Name": "QEventDispatcher on macOS",
"QDocModule": "qtcore",
"QtUsage": "Used in Qt Core on macOS.",
- "Path": "qeventdispatcher_cf_p.h",
+ "Files": "qeventdispatcher_cf_p.h",
"Description": "Treat as final version; no upstream known",
"Description": "Implementation of QAbstractEventDispatcher for macOS.",
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 376b13e9f2..8a94603488 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -3,6 +3,8 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qtimer.h"
+#include "qtimer_p.h"
+
#include "qabstracteventdispatcher.h"
#include "qcoreapplication.h"
#include "qobject_p.h"
@@ -12,23 +14,6 @@
QT_BEGIN_NAMESPACE
-static constexpr int INV_TIMER = -1; // invalid timer id
-
-class QTimerPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QTimer)
-public:
- void setInterval(int msec) { q_func()->setInterval(msec); }
- bool isActiveActualCalculation() const { return id >= 0; }
-
- int id = INV_TIMER;
- Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, int, inter, &QTimerPrivate::setInterval, 0)
- Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, bool, single, false)
- Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, Qt::TimerType, type, Qt::CoarseTimer)
- Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData,
- &QTimerPrivate::isActiveActualCalculation)
-};
-
/*!
\class QTimer
\inmodule QtCore
@@ -139,7 +124,7 @@ QTimer::QTimer(QObject *parent)
QTimer::~QTimer()
{
- if (d_func()->id != INV_TIMER) // stop running timer
+ if (d_func()->id != QTimerPrivate::INV_TIMER) // stop running timer
stop();
}
@@ -200,7 +185,7 @@ int QTimer::timerId() const
void QTimer::start()
{
Q_D(QTimer);
- if (d->id != INV_TIMER) // stop running timer
+ if (d->id != QTimerPrivate::INV_TIMER) // stop running timer
stop();
d->id = QObject::startTimer(d->inter, d->type);
d->isActiveData.notify();
@@ -239,9 +224,9 @@ void QTimer::start(int msec)
void QTimer::stop()
{
Q_D(QTimer);
- if (d->id != INV_TIMER) {
+ if (d->id != QTimerPrivate::INV_TIMER) {
QObject::killTimer(d->id);
- d->id = INV_TIMER;
+ d->id = QTimerPrivate::INV_TIMER;
d->isActiveData.notify();
}
}
@@ -721,7 +706,7 @@ void QTimer::setInterval(int msec)
Q_D(QTimer);
const bool intervalChanged = msec != d->inter;
d->inter.setValue(msec);
- if (d->id != INV_TIMER) { // create new timer
+ if (d->id != QTimerPrivate::INV_TIMER) { // create new timer
QObject::killTimer(d->id); // restart timer
d->id = QObject::startTimer(msec, d->type);
// No need to call markDirty() for d->isActiveData here,
@@ -755,7 +740,7 @@ QBindable<int> QTimer::bindableInterval()
int QTimer::remainingTime() const
{
Q_D(const QTimer);
- if (d->id != INV_TIMER) {
+ if (d->id != QTimerPrivate::INV_TIMER) {
return QAbstractEventDispatcher::instance()->remainingTime(d->id);
}
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index ca8a81c889..00c06186c3 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -11,9 +11,7 @@
#include <QtCore/qbasictimer.h> // conceptual inheritance
#include <QtCore/qobject.h>
-#if __has_include(<chrono>)
-# include <chrono>
-#endif
+#include <chrono>
QT_BEGIN_NAMESPACE
@@ -145,7 +143,6 @@ Q_SIGNALS:
void timeout(QPrivateSignal);
public:
-#if __has_include(<chrono>) || defined(Q_QDOC)
void setInterval(std::chrono::milliseconds value)
{
setInterval(int(value.count()));
@@ -175,7 +172,6 @@ public:
{
start(int(value.count()));
}
-#endif
protected:
void timerEvent(QTimerEvent *) override;
@@ -192,7 +188,6 @@ private:
static void singleShotImpl(int msec, Qt::TimerType timerType,
const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj);
-#if __has_include(<chrono>)
static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval)
{ return defaultTypeFor(int(interval.count())); }
@@ -202,7 +197,6 @@ private:
singleShotImpl(int(interval.count()),
timerType, receiver, slotObj);
}
-#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qtimer_p.h b/src/corelib/kernel/qtimer_p.h
new file mode 100644
index 0000000000..f283a264fa
--- /dev/null
+++ b/src/corelib/kernel/qtimer_p.h
@@ -0,0 +1,39 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#ifndef QTIMER_P_H
+#define QTIMER_P_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of the Qt translation tools. This header file may change from version
+// to version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "qobject_p.h"
+#include "qproperty_p.h"
+#include "qtimer.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTimerPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QTimer)
+public:
+ static constexpr int INV_TIMER = -1; // invalid timer id
+
+ void setInterval(int msec) { q_func()->setInterval(msec); }
+ bool isActiveActualCalculation() const { return id >= 0; }
+
+ int id = INV_TIMER;
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, int, inter, &QTimerPrivate::setInterval, 0)
+ Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, bool, single, false)
+ Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, Qt::TimerType, type, Qt::CoarseTimer)
+ Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData,
+ &QTimerPrivate::isActiveActualCalculation)
+};
+
+QT_END_NAMESPACE
+#endif // QTIMER_P_H
diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp
index 48ce893988..34225a809d 100644
--- a/src/corelib/kernel/qtimerinfo_unix.cpp
+++ b/src/corelib/kernel/qtimerinfo_unix.cpp
@@ -390,7 +390,7 @@ int QTimerInfoList::timerRemainingTime(int timerId)
repairTimersIfNeeded();
timespec tm = {0, 0};
- for (int i = 0; i < count(); ++i) {
+ for (int i = 0; i < size(); ++i) {
QTimerInfo *t = at(i);
if (t->id == timerId) {
if (currentTime < t->timeout) {
@@ -475,7 +475,7 @@ void QTimerInfoList::registerTimer(int timerId, qint64 interval, Qt::TimerType t
bool QTimerInfoList::unregisterTimer(int timerId)
{
// set timer inactive
- for (int i = 0; i < count(); ++i) {
+ for (int i = 0; i < size(); ++i) {
QTimerInfo *t = at(i);
if (t->id == timerId) {
// found it
@@ -496,7 +496,7 @@ bool QTimerInfoList::unregisterTimers(QObject *object)
{
if (isEmpty())
return false;
- for (int i = 0; i < count(); ++i) {
+ for (int i = 0; i < size(); ++i) {
QTimerInfo *t = at(i);
if (t->obj == object) {
// object found
@@ -516,7 +516,7 @@ bool QTimerInfoList::unregisterTimers(QObject *object)
QList<QAbstractEventDispatcher::TimerInfo> QTimerInfoList::registeredTimers(QObject *object) const
{
QList<QAbstractEventDispatcher::TimerInfo> list;
- for (int i = 0; i < count(); ++i) {
+ for (int i = 0; i < size(); ++i) {
const QTimerInfo * const t = at(i);
if (t->obj == object) {
list << QAbstractEventDispatcher::TimerInfo(t->id,
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 1824153966..521503b96b 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -449,7 +449,7 @@ bool QTranslator::load(const QString & filename, const QString & directory,
QString prefix;
if (QFileInfo(filename).isRelative()) {
prefix = directory;
- if (prefix.length() && !prefix.endsWith(u'/'))
+ if (prefix.size() && !prefix.endsWith(u'/'))
prefix += u'/';
}
@@ -472,7 +472,7 @@ bool QTranslator::load(const QString & filename, const QString & directory,
break;
int rightmost = 0;
- for (int i = 0; i < (int)delims.length(); i++) {
+ for (int i = 0; i < (int)delims.size(); i++) {
int k = fname.lastIndexOf(delims[i]);
if (k > rightmost)
rightmost = k;
@@ -620,17 +620,22 @@ static QString find_translation(const QLocale & locale,
// see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration
+ // For each language_country returned by locale.uiLanguages(), add
+ // also a lowercase version to the list. Since these languages are
+ // used to create file names, this is important on case-sensitive
+ // file systems, where otherwise a file called something like
+ // "prefix_en_us.qm" won't be found under the "en_US" locale. Note
+ // that the Qt resource system is always case-sensitive, even on
+ // Windows (in other words: this codepath is *not* UNIX-only).
QStringList languages = locale.uiLanguages();
-#if defined(Q_OS_UNIX)
for (int i = languages.size()-1; i >= 0; --i) {
QString lang = languages.at(i);
QString lowerLang = lang.toLower();
if (lang != lowerLang)
languages.insert(i + 1, lowerLang);
}
-#endif
- for (QString localeName : qAsConst(languages)) {
+ for (QString localeName : std::as_const(languages)) {
localeName.replace(u'-', u'_');
// try the complete locale name first and progressively truncate from
@@ -909,7 +914,7 @@ end:
if (!tn)
return QString();
QString str(tn_length / 2, Qt::Uninitialized);
- qFromBigEndian<ushort>(tn, str.length(), str.data());
+ qFromBigEndian<ushort>(tn, str.size(), str.data());
return str;
}
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 94d062f633..922def97d6 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1069,7 +1069,7 @@ void QVariant::clear()
/*!
\fn QVariant::Type QVariant::nameToType(const char *name)
- \deprecated [6.0] Use \c QMetaType.fromName(name).id() instead
+ \deprecated [6.0] Use \c QMetaType::fromName(name).id() instead
Converts the string representation of the storage type given in \a
name, to its enum representation.
@@ -1312,9 +1312,21 @@ void QVariant::save(QDataStream &s) const
/*!
\since 4.4
+ \relates QVariant
Reads a variant \a p from the stream \a s.
+ \note If the stream contains types that aren't the built-in ones (see \l
+ QMetaType::Type), those types must be registered using qRegisterMetaType()
+ or QMetaType::registerType() before the variant can be properly loaded. If
+ an unregistered type is found, QVariant will set the corrupt flag in the
+ stream, stop processing and print a warning. For example, for QList<int>
+ it would print the following:
+
+ \quotation
+ QVariant::load: unknown user type with name QList<int>
+ \endquotation
+
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/
QDataStream &operator>>(QDataStream &s, QVariant &p)
@@ -1325,6 +1337,7 @@ QDataStream &operator>>(QDataStream &s, QVariant &p)
/*!
Writes a variant \a p to the stream \a s.
+ \relates QVariant
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/
@@ -1390,8 +1403,13 @@ QString QVariant::toString() const
}
/*!
- Returns the variant as a QMap<QString, QVariant> if the variant
- has type() \l QMetaType::QVariantMap; otherwise returns an empty map.
+ Returns the variant as a QVariantMap if the variant has type() \l
+ QMetaType::QVariantMap. If it doesn't, QVariant will attempt to
+ convert the type to a map and then return it. This will succeed for
+ any type that has registered a converter to QVariantMap or which was
+ declared as a associative container using
+ \l{Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE}. If none of those
+ conditions are true, this function will return an empty map.
\sa canConvert(), convert()
*/
@@ -1941,9 +1959,13 @@ qreal QVariant::toReal(bool *ok) const
}
/*!
- Returns the variant as a QVariantList if the variant has userType()
- \l QMetaType::QVariantList or \l QMetaType::QStringList; otherwise returns
- an empty list.
+ Returns the variant as a QVariantList if the variant has userType() \l
+ QMetaType::QVariantList. If it doesn't, QVariant will attempt to convert
+ the type to a list and then return it. This will succeed for any type that
+ has registered a converter to QVariantList or which was declared as a
+ sequential container using \l{Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE}. If
+ none of those conditions are true, this function will return an empty
+ list.
\sa canConvert(), convert()
*/
@@ -2595,9 +2617,6 @@ QT_WARNING_POP
\snippet code/src_corelib_kernel_qvariant.cpp 7
- \note If you are working with custom types, you should use
- the Q_DECLARE_METATYPE() macro to register your custom type.
-
\sa setValue(), value()
*/
diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp
index 6d6b322229..c55904c1d0 100644
--- a/src/corelib/mimetypes/qmimedatabase.cpp
+++ b/src/corelib/mimetypes/qmimedatabase.cpp
@@ -357,7 +357,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
// Pass 1) Try to match on the file name
QMimeGlobMatchResult candidatesByName = findByFileName(fileName);
- if (candidatesByName.m_allMatchingMimeTypes.count() == 1) {
+ if (candidatesByName.m_allMatchingMimeTypes.size() == 1) {
const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
if (mime.isValid())
return mime;
@@ -386,7 +386,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
if (candidatesByName.m_matchingMimeTypes.contains(sniffedMime)) {
return candidateByData;
}
- for (const QString &m : qAsConst(candidatesByName.m_allMatchingMimeTypes)) {
+ for (const QString &m : std::as_const(candidatesByName.m_allMatchingMimeTypes)) {
if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match
return mimeTypeForName(m);
@@ -399,7 +399,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
}
}
- if (candidatesByName.m_allMatchingMimeTypes.count() > 1) {
+ if (candidatesByName.m_allMatchingMimeTypes.size() > 1) {
candidatesByName.m_matchingMimeTypes.sort(); // make it deterministic
const QMimeType mime = mimeTypeForName(candidatesByName.m_matchingMimeTypes.at(0));
if (mime.isValid())
@@ -444,31 +444,32 @@ QMimeType QMimeDatabasePrivate::mimeTypeForData(QIODevice *device)
}
QMimeType QMimeDatabasePrivate::mimeTypeForFile(const QString &fileName,
- [[maybe_unused]] const QFileInfo *fileInfo,
+ const QFileInfo &fileInfo,
QMimeDatabase::MatchMode mode)
{
+ if (false) {
#ifdef Q_OS_UNIX
- // Cannot access statBuf.st_mode from the filesystem engine, so we have to stat again.
- // In addition we want to follow symlinks.
- const QByteArray nativeFilePath = QFile::encodeName(fileName);
- QT_STATBUF statBuffer;
- if (QT_STAT(nativeFilePath.constData(), &statBuffer) == 0) {
- if (S_ISDIR(statBuffer.st_mode))
- return mimeTypeForName(directoryMimeType());
- if (S_ISCHR(statBuffer.st_mode))
- return mimeTypeForName(QStringLiteral("inode/chardevice"));
- if (S_ISBLK(statBuffer.st_mode))
- return mimeTypeForName(QStringLiteral("inode/blockdevice"));
- if (S_ISFIFO(statBuffer.st_mode))
- return mimeTypeForName(QStringLiteral("inode/fifo"));
- if (S_ISSOCK(statBuffer.st_mode))
- return mimeTypeForName(QStringLiteral("inode/socket"));
- }
-#else
- const bool isDirectory = fileInfo ? fileInfo->isDir() : QFileInfo(fileName).isDir();
- if (isDirectory)
- return mimeTypeForName(directoryMimeType());
+ } else if (fileInfo.isNativePath()) {
+ // If this is a local file, we'll want to do a stat() ourselves so we can
+ // detect additional inode types. In addition we want to follow symlinks.
+ const QByteArray nativeFilePath = QFile::encodeName(fileName);
+ QT_STATBUF statBuffer;
+ if (QT_STAT(nativeFilePath.constData(), &statBuffer) == 0) {
+ if (S_ISDIR(statBuffer.st_mode))
+ return mimeTypeForName(directoryMimeType());
+ if (S_ISCHR(statBuffer.st_mode))
+ return mimeTypeForName(QStringLiteral("inode/chardevice"));
+ if (S_ISBLK(statBuffer.st_mode))
+ return mimeTypeForName(QStringLiteral("inode/blockdevice"));
+ if (S_ISFIFO(statBuffer.st_mode))
+ return mimeTypeForName(QStringLiteral("inode/fifo"));
+ if (S_ISSOCK(statBuffer.st_mode))
+ return mimeTypeForName(QStringLiteral("inode/socket"));
+ }
#endif
+ } else if (fileInfo.isDir()) {
+ return mimeTypeForName(directoryMimeType());
+ }
switch (mode) {
case QMimeDatabase::MatchDefault:
@@ -615,7 +616,7 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mo
{
QMutexLocker locker(&d->mutex);
- return d->mimeTypeForFile(fileInfo.filePath(), &fileInfo, mode);
+ return d->mimeTypeForFile(fileInfo.filePath(), fileInfo, mode);
}
/*!
@@ -630,7 +631,8 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode
if (mode == MatchExtension) {
return d->mimeTypeForFileExtension(fileName);
} else {
- return d->mimeTypeForFile(fileName, nullptr, mode);
+ QFileInfo fileInfo(fileName);
+ return d->mimeTypeForFile(fileName, fileInfo, mode);
}
}
@@ -652,7 +654,7 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
const QStringList matches = d->mimeTypeForFileName(fileName);
QList<QMimeType> mimes;
- mimes.reserve(matches.count());
+ mimes.reserve(matches.size());
for (const QString &mime : matches)
mimes.append(d->mimeTypeForName(mime));
return mimes;
diff --git a/src/corelib/mimetypes/qmimedatabase_p.h b/src/corelib/mimetypes/qmimedatabase_p.h
index 2dd8ecf984..96981ba3fe 100644
--- a/src/corelib/mimetypes/qmimedatabase_p.h
+++ b/src/corelib/mimetypes/qmimedatabase_p.h
@@ -60,7 +60,7 @@ public:
QMimeType mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device);
QMimeType mimeTypeForFileExtension(const QString &fileName);
QMimeType mimeTypeForData(QIODevice *device);
- QMimeType mimeTypeForFile(const QString &fileName, const QFileInfo *fileInfo, QMimeDatabase::MatchMode mode);
+ QMimeType mimeTypeForFile(const QString &fileName, const QFileInfo &fileInfo, QMimeDatabase::MatchMode mode);
QMimeType findByData(const QByteArray &data, int *priorityPtr);
QStringList mimeTypeForFileName(const QString &fileName);
QMimeGlobMatchResult findByFileName(const QString &fileName);
diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp
index f991d15b6c..381b635b90 100644
--- a/src/corelib/mimetypes/qmimeglobpattern.cpp
+++ b/src/corelib/mimetypes/qmimeglobpattern.cpp
@@ -34,9 +34,9 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
bool replace = weight > m_weight;
if (!replace) {
// Compare the length of the match
- if (pattern.length() < m_matchingPatternLength)
+ if (pattern.size() < m_matchingPatternLength)
return; // too short, ignore
- else if (pattern.length() > m_matchingPatternLength) {
+ else if (pattern.size() > m_matchingPatternLength) {
// longer: clear any previous match (like *.bz2, when pattern is *.tar.bz2)
replace = true;
}
@@ -44,7 +44,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
if (replace) {
m_matchingMimeTypes.clear();
// remember the new "longer" length
- m_matchingPatternLength = pattern.length();
+ m_matchingPatternLength = pattern.size();
m_weight = weight;
}
if (!m_matchingMimeTypes.contains(mimeType)) {
@@ -59,7 +59,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(const QString &pattern) const
{
- const int patternLength = pattern.length();
+ const int patternLength = pattern.size();
if (!patternLength)
return OtherPattern;
@@ -108,10 +108,10 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFileName) const
const QString fileName = m_caseSensitivity == Qt::CaseInsensitive
? inputFileName.toLower() : inputFileName;
- const int patternLength = m_pattern.length();
+ const int patternLength = m_pattern.size();
if (!patternLength)
return false;
- const int fileNameLength = fileName.length();
+ const int fileNameLength = fileName.size();
switch (m_patternType) {
case SuffixPattern: {
@@ -166,7 +166,7 @@ static bool isSimplePattern(const QString &pattern)
{
// starts with "*.", has no other '*'
return pattern.lastIndexOf(u'*') == 0
- && pattern.length() > 1
+ && pattern.size() > 1
&& pattern.at(1) == u'.' // (other dots are OK, like *.tar.bz2)
// and contains no other special character
&& !pattern.contains(u'?')
@@ -229,7 +229,7 @@ void QMimeGlobPatternList::match(QMimeGlobMatchResult &result,
const QMimeGlobPattern &glob = *it;
if (glob.matchFileName(fileName)) {
const QString pattern = glob.pattern();
- const int suffixLen = isSimplePattern(pattern) ? pattern.length() - 2 : 0;
+ const int suffixLen = isSimplePattern(pattern) ? pattern.size() - 2 : 0;
result.addMatch(glob.mimeType(), glob.weight(), pattern, suffixLen);
}
}
@@ -244,7 +244,7 @@ void QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QMimeGlobMatch
// (which is most of them, so this optimization is definitely worth it)
const int lastDot = fileName.lastIndexOf(u'.');
if (lastDot != -1) { // if no '.', skip the extension lookup
- const int ext_len = fileName.length() - lastDot - 1;
+ const int ext_len = fileName.size() - lastDot - 1;
const QString simpleExtension = fileName.right(ext_len).toLower();
// (toLower because fast patterns are always case-insensitive and saved as lowercase)
diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp
index cbb1ccd527..ac27d365ac 100644
--- a/src/corelib/mimetypes/qmimeprovider.cpp
+++ b/src/corelib/mimetypes/qmimeprovider.cpp
@@ -219,9 +219,9 @@ void QMimeBinaryProvider::addFileNameMatches(const QString &fileName, QMimeGlobM
const int reverseSuffixTreeOffset = m_cacheFile->getUint32(PosReverseSuffixTreeOffset);
const int numRoots = m_cacheFile->getUint32(reverseSuffixTreeOffset);
const int firstRootOffset = m_cacheFile->getUint32(reverseSuffixTreeOffset + 4);
- matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, lowerFileName, lowerFileName.length() - 1, false);
+ matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, lowerFileName, lowerFileName.size() - 1, false);
if (result.m_matchingMimeTypes.isEmpty())
- matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true);
+ matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, fileName, fileName.size() - 1, true);
}
// Check complex globs (e.g. "callgrind.out[0-9]*" or "README*")
if (result.m_matchingMimeTypes.isEmpty())
@@ -448,11 +448,11 @@ void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result)
{
loadMimeTypeList();
if (result.isEmpty()) {
- result.reserve(m_mimetypeNames.count());
- for (const QString &name : qAsConst(m_mimetypeNames))
+ result.reserve(m_mimetypeNames.size());
+ for (const QString &name : std::as_const(m_mimetypeNames))
result.append(mimeTypeForNameUnchecked(name));
} else {
- for (const QString &name : qAsConst(m_mimetypeNames))
+ for (const QString &name : std::as_const(m_mimetypeNames))
if (std::find_if(result.constBegin(), result.constEnd(), [name](const QMimeType &mime) -> bool { return mime.name() == name; })
== result.constEnd())
result.append(mimeTypeForNameUnchecked(name));
@@ -680,7 +680,7 @@ void QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr, QMi
{
QString candidateName;
bool foundOne = false;
- for (const QMimeMagicRuleMatcher &matcher : qAsConst(m_magicMatchers)) {
+ for (const QMimeMagicRuleMatcher &matcher : std::as_const(m_magicMatchers)) {
if (matcher.matches(data)) {
const int priority = matcher.priority();
if (priority > *accuracyPtr) {
@@ -700,7 +700,7 @@ void QMimeXMLProvider::ensureLoaded()
const QString packageDir = m_directory + QStringLiteral("/packages");
QDir dir(packageDir);
const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
- allFiles.reserve(files.count());
+ allFiles.reserve(files.size());
for (const QString &xmlFile : files)
allFiles.append(packageDir + u'/' + xmlFile);
@@ -716,7 +716,7 @@ void QMimeXMLProvider::ensureLoaded()
//qDebug() << "Loading" << m_allFiles;
- for (const QString &file : qAsConst(allFiles))
+ for (const QString &file : std::as_const(allFiles))
load(file);
}
diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp
index c578f3cad0..24780ffe27 100644
--- a/src/corelib/mimetypes/qmimetype.cpp
+++ b/src/corelib/mimetypes/qmimetype.cpp
@@ -225,7 +225,7 @@ QString QMimeType::comment() const
languageList << QLocale().name();
languageList << QLocale().uiLanguages();
languageList << u"default"_s; // use the default locale if possible.
- for (const QString &language : qAsConst(languageList)) {
+ for (const QString &language : std::as_const(languageList)) {
const QString lang = language == "C"_L1 ? u"en_US"_s : language;
const QString comm = d->localeComments.value(lang);
if (!comm.isEmpty())
@@ -410,10 +410,10 @@ QStringList QMimeType::suffixes() const
QMimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<QMimeTypePrivate&>(*d));
QStringList result;
- for (const QString &pattern : qAsConst(d->globPatterns)) {
+ for (const QString &pattern : std::as_const(d->globPatterns)) {
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
if (pattern.startsWith("*."_L1) &&
- pattern.length() > 2 &&
+ pattern.size() > 2 &&
pattern.indexOf(u'*', 2) < 0 && pattern.indexOf(u'?', 2) < 0) {
const QString suffix = pattern.mid(2);
result.append(suffix);
diff --git a/src/corelib/platform/android/qandroidextras.cpp b/src/corelib/platform/android/qandroidextras.cpp
index 0fa67eacaf..4bf7bd9442 100644
--- a/src/corelib/platform/android/qandroidextras.cpp
+++ b/src/corelib/platform/android/qandroidextras.cpp
@@ -117,6 +117,7 @@ QAndroidBinder QAndroidParcelPrivate::readBinder() const
/*!
\class QAndroidParcel
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\brief Wraps the most important methods of Android Parcel class.
@@ -125,6 +126,8 @@ QAndroidBinder QAndroidParcelPrivate::readBinder() const
\l {https://developer.android.com/reference/android/os/Parcel.html}{Android Parcel}
methods.
+ \include qtcore.qdoc qtcoreprivate-usage
+
\since 6.2
*/
@@ -233,6 +236,7 @@ QJniObject QAndroidParcel::handle() const
/*!
\class QAndroidBinder
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\brief Wraps the most important methods of Android Binder class.
@@ -241,6 +245,8 @@ QJniObject QAndroidParcel::handle() const
\l {https://developer.android.com/reference/android/os/Binder.html}{Android Binder}
methods.
+ \include qtcore.qdoc qtcoreprivate-usage
+
\since 6.2
*/
@@ -370,6 +376,7 @@ QJniObject QAndroidBinder::handle() const
/*!
\class QAndroidServiceConnection
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\brief Wraps the most important methods of Android ServiceConnection class.
@@ -380,6 +387,8 @@ QJniObject QAndroidBinder::handle() const
It is useful when you perform a QtAndroidPrivate::bindService operation.
+ \include qtcore.qdoc qtcoreprivate-usage
+
\since 6.2
*/
@@ -496,6 +505,7 @@ public:
/*!
\class QAndroidActivityResultReceiver
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\since 6.2
@@ -503,6 +513,8 @@ public:
Create a subclass of this class to be notified of the results when using the
\c QtAndroidPrivate::startActivity() and \c QtAndroidPrivate::startIntentSender() APIs.
+
+ \include qtcore.qdoc qtcoreprivate-usage
*/
/*!
@@ -591,6 +603,7 @@ public:
/*!
\class QAndroidService
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\brief Wraps the most important methods of Android Service class.
@@ -599,6 +612,8 @@ public:
\l {https://developer.android.com/reference/android/app/Service.html}{Android Service}
methods.
+ \include qtcore.qdoc qtcoreprivate-usage
+
\since 6.2
*/
@@ -660,6 +675,7 @@ QAndroidBinder* QAndroidService::onBind(const QAndroidIntent &/*intent*/)
/*!
\class QAndroidIntent
+ \inheaderfile QtCore/private/qandroidextras_p.h
\preliminary
\inmodule QtCorePrivate
\brief Wraps the most important methods of Android Intent class.
@@ -668,6 +684,8 @@ QAndroidBinder* QAndroidService::onBind(const QAndroidIntent &/*intent*/)
\l {https://developer.android.com/reference/android/content/Intent.html}{Android Intent}
methods.
+ \include qtcore.qdoc qtcoreprivate-usage
+
\since 6.2
*/
@@ -793,6 +811,8 @@ QJniObject QAndroidIntent::handle() const
\brief The QtAndroidPrivate namespace provides miscellaneous functions
to aid Android development.
\inheaderfile QtCore/private/qandroidextras_p.h
+
+ \include qtcore.qdoc qtcoreprivate-usage
*/
/*!
diff --git a/src/corelib/platform/android/qandroidnativeinterface.cpp b/src/corelib/platform/android/qandroidnativeinterface.cpp
index a93844139b..dde1b1fddf 100644
--- a/src/corelib/platform/android/qandroidnativeinterface.cpp
+++ b/src/corelib/platform/android/qandroidnativeinterface.cpp
@@ -7,8 +7,10 @@
#include <QtCore/private/qjnihelpers_p.h>
#include <QtCore/qjniobject.h>
#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
-#include <QtConcurrent/QtConcurrent>
+#include <QtCore/qfuture.h>
+#include <QtCore/qfuturewatcher.h>
#include <QtCore/qpromise.h>
+#include <QtCore/qthreadpool.h>
#include <deque>
#endif
@@ -17,8 +19,12 @@ QT_BEGIN_NAMESPACE
#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
static const char qtNativeClassName[] = "org/qtproject/qt/android/QtNative";
-typedef std::pair<std::function<QVariant()>, QSharedPointer<QPromise<QVariant>>> RunnablePair;
-typedef std::deque<RunnablePair> PendingRunnables;
+struct PendingRunnable {
+ std::function<QVariant()> function;
+ QSharedPointer<QPromise<QVariant>> promise;
+};
+
+using PendingRunnables = std::deque<PendingRunnable>;
Q_GLOBAL_STATIC(PendingRunnables, g_pendingRunnables);
static QBasicMutex g_pendingRunnablesMutex;
#endif
@@ -159,8 +165,8 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
QFuture<QVariant> future = promise->future();
promise->start();
- (void) QtConcurrent::run([=, &future]() {
- if (!timeout.isForever()) {
+ if (!timeout.isForever()) {
+ QThreadPool::globalInstance()->start([=]() mutable {
QEventLoop loop;
QTimer::singleShot(timeout.remainingTime(), &loop, [&]() {
future.cancel();
@@ -176,12 +182,24 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
loop.quit();
});
watcher.setFuture(future);
+
+ // we're going to sleep, make sure we don't block
+ // QThreadPool::globalInstance():
+
+ QThreadPool::globalInstance()->releaseThread();
+ const auto sg = qScopeGuard([] {
+ QThreadPool::globalInstance()->reserveThread();
+ });
loop.exec();
- }
- });
+ });
+ }
QMutexLocker locker(&g_pendingRunnablesMutex);
- g_pendingRunnables->push_back(std::pair(runnable, promise));
+#ifdef __cpp_aggregate_paren_init
+ g_pendingRunnables->emplace_back(runnable, std::move(promise));
+#else
+ g_pendingRunnables->push_back({runnable, std::move(promise)});
+#endif
locker.unlock();
QJniObject::callStaticMethod<void>(qtNativeClassName,
@@ -199,15 +217,14 @@ static void runPendingCppRunnables(JNIEnv */*env*/, jobject /*obj*/)
if (g_pendingRunnables->empty())
break;
- std::pair pair = std::move(g_pendingRunnables->front());
+ PendingRunnable r = std::move(g_pendingRunnables->front());
g_pendingRunnables->pop_front();
locker.unlock();
// run the runnable outside the sync block!
- auto promise = pair.second;
- if (!promise->isCanceled())
- promise->addResult(pair.first());
- promise->finish();
+ if (!r.promise->isCanceled())
+ r.promise->addResult(r.function());
+ r.promise->finish();
}
}
#endif
diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp
index a915c031fe..cd3750ff73 100644
--- a/src/corelib/platform/wasm/qstdweb.cpp
+++ b/src/corelib/platform/wasm/qstdweb.cpp
@@ -225,7 +225,7 @@ Uint8Array::Uint8Array(const ArrayBuffer &buffer, uint32_t offset, uint32_t leng
// Constructs a Uint8Array which references an area on the heap.
Uint8Array::Uint8Array(const char *buffer, uint32_t size)
-:m_uint8Array(Uint8Array::constructor_().new_(Uint8Array::heap().buffer().m_arrayBuffer, uint32_t(buffer), size))
+:m_uint8Array(Uint8Array::constructor_().new_(Uint8Array::heap().buffer().m_arrayBuffer, uintptr_t(buffer), size))
{
}
diff --git a/src/corelib/platform/windows/qfactorycacheregistration.cpp b/src/corelib/platform/windows/qfactorycacheregistration.cpp
new file mode 100644
index 0000000000..6bd69c66d1
--- /dev/null
+++ b/src/corelib/platform/windows/qfactorycacheregistration.cpp
@@ -0,0 +1,53 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qfactorycacheregistration_p.h"
+
+#include <QtCore/QMutex>
+
+QT_BEGIN_NAMESPACE
+
+#ifdef QT_USE_FACTORY_CACHE_REGISTRATION
+
+static QBasicMutex registrationMutex;
+static detail::QWinRTFactoryCacheRegistration *firstElement;
+
+detail::QWinRTFactoryCacheRegistration::QWinRTFactoryCacheRegistration(
+ QFunctionPointer clearFunction)
+ : m_clearFunction(clearFunction)
+{
+ QMutexLocker lock(&registrationMutex);
+
+ // forward pointers
+ m_next = std::exchange(firstElement, this);
+
+ // backward pointers
+ m_prevNext = &firstElement;
+ if (m_next)
+ m_next->m_prevNext = &m_next;
+}
+
+detail::QWinRTFactoryCacheRegistration::~QWinRTFactoryCacheRegistration()
+{
+ QMutexLocker lock(&registrationMutex);
+
+ *m_prevNext = m_next;
+
+ if (m_next)
+ m_next->m_prevNext = m_prevNext;
+}
+
+void detail::QWinRTFactoryCacheRegistration::clearAllCaches()
+{
+ QMutexLocker lock(&registrationMutex);
+
+ detail::QWinRTFactoryCacheRegistration *element;
+
+ for (element = firstElement; element != nullptr; element = element->m_next) {
+ element->m_clearFunction();
+ }
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/corelib/platform/windows/qfactorycacheregistration_p.h b/src/corelib/platform/windows/qfactorycacheregistration_p.h
new file mode 100644
index 0000000000..f450062fc4
--- /dev/null
+++ b/src/corelib/platform/windows/qfactorycacheregistration_p.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QFACTORYCACHEREGISTRATION_P_H
+#define QFACTORYCACHEREGISTRATION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+#if !defined(QT_BOOTSTRAPPED) && defined(Q_OS_WIN) && !defined(Q_CC_CLANG) && QT_CONFIG(cpp_winrt)
+# define QT_USE_FACTORY_CACHE_REGISTRATION
+#endif
+
+#ifdef QT_USE_FACTORY_CACHE_REGISTRATION
+
+#include "qt_winrtbase_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace detail {
+
+class QWinRTFactoryCacheRegistration
+{
+public:
+ Q_CORE_EXPORT explicit QWinRTFactoryCacheRegistration(QFunctionPointer clearFunction);
+ Q_CORE_EXPORT ~QWinRTFactoryCacheRegistration();
+ Q_CORE_EXPORT static void clearAllCaches();
+
+ Q_DISABLE_COPY_MOVE(QWinRTFactoryCacheRegistration)
+private:
+ QWinRTFactoryCacheRegistration **m_prevNext = nullptr;
+ QWinRTFactoryCacheRegistration *m_next = nullptr;
+ QFunctionPointer m_clearFunction;
+};
+
+inline QWinRTFactoryCacheRegistration reg([]() noexcept { winrt::clear_factory_cache(); });
+}
+
+QT_END_NAMESPACE
+
+#endif
+#endif // QFACTORYCACHEREGISTRATION_P_H
diff --git a/src/corelib/platform/windows/qt_winrtbase_p.h b/src/corelib/platform/windows/qt_winrtbase_p.h
new file mode 100644
index 0000000000..fb7366f93d
--- /dev/null
+++ b/src/corelib/platform/windows/qt_winrtbase_p.h
@@ -0,0 +1,34 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QT_WINRTBASE_P_H
+#define QT_WINRTBASE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+#if QT_CONFIG(cpp_winrt)
+# include <winrt/base.h>
+# include <QtCore/private/qfactorycacheregistration_p.h>
+// Workaround for Windows SDK bug.
+// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
+namespace winrt::impl
+{
+ template <typename Async>
+ auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
+}
+// See https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/faq#how-do-i-resolve-ambiguities-with-getcurrenttime-and-or-try-
+// for more workarounds.
+#endif // QT_CONFIG(cpp/winrt)
+
+#endif // QT_WINRTBASE_P_H
diff --git a/src/corelib/plugin/qcoffpeparser.cpp b/src/corelib/plugin/qcoffpeparser.cpp
index e037f135d1..054a433603 100644
--- a/src/corelib/plugin/qcoffpeparser.cpp
+++ b/src/corelib/plugin/qcoffpeparser.cpp
@@ -40,7 +40,7 @@ static const WORD ExpectedMachine =
#if 0
// nothing, just so everything is #elf
#elif defined(Q_PROCESSOR_ARM_32)
- IMAGE_FILE_MACHINE_ARM
+ IMAGE_FILE_MACHINE_ARMNT
#elif defined(Q_PROCESSOR_ARM_64)
IMAGE_FILE_MACHINE_ARM64
#elif defined(Q_PROCESSOR_IA64)
diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp
index b0c23d58b6..6ebfaff21e 100644
--- a/src/corelib/plugin/qelfparser_p.cpp
+++ b/src/corelib/plugin/qelfparser_p.cpp
@@ -20,6 +20,11 @@
# error "Need ELF header to parse plugins."
#endif
+// Support older ELFOSABI define for GNU/Linux
+#if !defined(ELFOSABI_GNU) && defined(ELFOSABI_LINUX)
+# define ELFOSABI_GNU ELFOSABI_LINUX
+#endif
+
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
@@ -128,10 +133,8 @@ struct ElfMachineCheck
#elif defined(Q_PROCESSOR_SH)
EM_SH
#elif defined(Q_PROCESSOR_SPARC_V9)
-# warning "Please confirm that this is correct for Linux and Solaris"
EM_SPARCV9
#elif defined(Q_PROCESSOR_SPARC_64)
-# warning "Please confirm that this is correct for Linux and Solaris"
EM_SPARCV9
#elif defined(Q_PROCESSOR_SPARC)
EM_SPARC
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index 4ee87d0dab..b59435e98c 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -132,7 +132,7 @@ Q_GLOBAL_STATIC(QFactoryLoaderGlobals, qt_factoryloader_global)
QFactoryLoaderPrivate::~QFactoryLoaderPrivate()
{
- for (QLibraryPrivate *library : qAsConst(libraryList))
+ for (QLibraryPrivate *library : std::as_const(libraryList))
library->release();
}
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 6a3f13bb81..48926830b4 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -207,7 +207,7 @@ static QLibraryScanResult qt_find_pattern(const char *s, qsizetype s_len, QStrin
information could not be read.
Returns true if version information is present and successfully read.
*/
-static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
+static QLibraryScanResult findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
{
QFile file(library);
if (!file.open(QIODevice::ReadOnly)) {
@@ -215,7 +215,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
lib->errorString = file.errorString();
qCWarning(qt_lcDebugPlugins, "%ls: cannot open: %ls", qUtf16Printable(library),
qUtf16Printable(file.errorString()));
- return false;
+ return {};
}
// Files can be bigger than the virtual memory size on 32-bit systems, so
@@ -232,7 +232,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
// This can't be used as a plugin.
qCWarning(qt_lcDebugPlugins, "%ls: failed to map to memory: %ls",
qUtf16Printable(library), qUtf16Printable(file.errorString()));
- return false;
+ return {};
}
#else
QByteArray data;
@@ -249,6 +249,10 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
QString errMsg = library;
QLibraryScanResult r = qt_find_pattern(filedata, fdlen, &errMsg);
if (r.length) {
+#if defined(Q_OF_MACH_O)
+ if (r.isEncrypted)
+ return r;
+#endif
if (!lib->metaData.parse(QByteArrayView(filedata + r.pos, r.length))) {
errMsg = lib->metaData.errorString();
qCWarning(qt_lcDebugPlugins, "Found invalid metadata in lib %ls: %ls",
@@ -257,7 +261,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
qCDebug(qt_lcDebugPlugins, "Found metadata in lib %ls, metadata=\n%s\n",
qUtf16Printable(library),
QJsonDocument(lib->metaData.toJson()).toJson().constData());
- return true;
+ return r;
}
} else {
qCDebug(qt_lcDebugPlugins, "Failed to find metadata in lib %ls: %ls",
@@ -266,7 +270,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
lib->errorString = QLibrary::tr("Failed to extract plugin meta data from '%1': %2")
.arg(library, errMsg);
- return false;
+ return {};
}
static void installCoverageTool(QLibraryPrivate *libPrivate)
@@ -362,7 +366,7 @@ inline void QLibraryStore::cleanup()
// dump all objects that remain
if (lcDebugLibrary().isDebugEnabled()) {
- for (QLibraryPrivate *lib : qAsConst(data->libraryMap)) {
+ for (QLibraryPrivate *lib : std::as_const(data->libraryMap)) {
if (lib)
qDebug(lcDebugLibrary)
<< "On QtCore unload," << lib->fileName << "was leaked, with"
@@ -722,7 +726,22 @@ void QLibraryPrivate::updatePluginState()
if (!pHnd.loadRelaxed()) {
// scan for the plugin metadata without loading
- success = findPatternUnloaded(fileName, this);
+ QLibraryScanResult result = findPatternUnloaded(fileName, this);
+#if defined(Q_OF_MACH_O)
+ if (result.length && result.isEncrypted) {
+ // We found the .qtmetadata section, but since the library is encrypted
+ // we need to dlopen() it before we can parse the metadata for further
+ // validation.
+ qCDebug(qt_lcDebugPlugins, "Library is encrypted. Doing prospective load before parsing metadata");
+ locker.unlock();
+ load();
+ locker.relock();
+ success = qt_get_metadata(this, &errorString);
+ } else
+#endif
+ {
+ success = result.length != 0;
+ }
} else {
// library is already loaded (probably via QLibrary)
// simply get the target function and call it.
@@ -911,13 +930,7 @@ QLibrary::~QLibrary()
void QLibrary::setFileName(const QString &fileName)
{
- QLibrary::LoadHints lh;
- if (d) {
- lh = d->loadHints();
- d->release();
- d = {};
- }
- d = QLibraryPrivate::findOrCreate(fileName, QString(), lh);
+ setFileNameAndVersion(fileName, QString());
}
QString QLibrary::fileName() const
@@ -940,13 +953,7 @@ QString QLibrary::fileName() const
*/
void QLibrary::setFileNameAndVersion(const QString &fileName, int verNum)
{
- QLibrary::LoadHints lh;
- if (d) {
- lh = d->loadHints();
- d->release();
- d = {};
- }
- d = QLibraryPrivate::findOrCreate(fileName, verNum >= 0 ? QString::number(verNum) : QString(), lh);
+ setFileNameAndVersion(fileName, verNum >= 0 ? QString::number(verNum) : QString());
}
/*!
@@ -964,9 +971,10 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver
if (d) {
lh = d->loadHints();
d->release();
- d = {};
}
- d = QLibraryPrivate::findOrCreate(fileName, version, lh);
+ QLibraryPrivate *dd = QLibraryPrivate::findOrCreate(fileName, version, lh);
+ d = dd;
+ d.setTag(isLoaded() ? Loaded : NotLoaded);
}
/*!
diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h
index 8c722a3283..e3bbbe104b 100644
--- a/src/corelib/plugin/qlibrary_p.h
+++ b/src/corelib/plugin/qlibrary_p.h
@@ -38,6 +38,9 @@ struct QLibraryScanResult
{
qsizetype pos;
qsizetype length;
+#if defined(Q_OF_MACH_O)
+ bool isEncrypted = false;
+#endif
};
class QLibraryStore;
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index 7ad6e9e335..898d5a2f6c 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -164,7 +164,7 @@ bool QLibraryPrivate::load_sys()
QStringList tmp;
qSwap(tmp, list);
list.reserve(tmp.size() * 2);
- for (const QString &s : qAsConst(tmp)) {
+ for (const QString &s : std::as_const(tmp)) {
QString modifiedPath = s;
f(&modifiedPath);
list.append(modifiedPath);
diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp
index 741dd8cff9..c95118e554 100644
--- a/src/corelib/plugin/qlibrary_win.cpp
+++ b/src/corelib/plugin/qlibrary_win.cpp
@@ -59,7 +59,7 @@ bool QLibraryPrivate::load_sys()
locker.unlock();
Handle hnd = nullptr;
- for (const QString &attempt : qAsConst(attempts)) {
+ for (const QString &attempt : std::as_const(attempts)) {
hnd = LoadLibrary(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(attempt).utf16()));
// If we have a handle or the last error is something other than "unable
diff --git a/src/corelib/plugin/qmachparser.cpp b/src/corelib/plugin/qmachparser.cpp
index 979ce2c7de..7a82b84cb3 100644
--- a/src/corelib/plugin/qmachparser.cpp
+++ b/src/corelib/plugin/qmachparser.cpp
@@ -56,6 +56,23 @@ static QLibraryScanResult notfound(const QString &reason, QString *errorString)
return {};
}
+static bool isEncrypted(const my_mach_header *header)
+{
+ auto commandCursor = uintptr_t(header) + sizeof(my_mach_header);
+ for (uint32_t i = 0; i < header->ncmds; ++i) {
+ load_command *loadCommand = reinterpret_cast<load_command *>(commandCursor);
+ if (loadCommand->cmd == LC_ENCRYPTION_INFO || loadCommand->cmd == LC_ENCRYPTION_INFO_64) {
+ // The layout of encryption_info_command and encryption_info_command_64 is the same
+ // up until and including cryptid, so we can treat it as encryption_info_command.
+ auto encryptionInfoCommand = reinterpret_cast<encryption_info_command*>(loadCommand);
+ return encryptionInfoCommand->cryptid != 0;
+ }
+ commandCursor += loadCommand->cmdsize;
+ }
+
+ return false;
+}
+
QLibraryScanResult QMachOParser::parse(const char *m_s, ulong fdlen, QString *errorString)
{
// The minimum size of a Mach-O binary we're interested in.
@@ -166,8 +183,12 @@ QLibraryScanResult QMachOParser::parse(const char *m_s, ulong fdlen, QString *e
if (sect[j].size < sizeof(QPluginMetaData::MagicHeader))
return notfound(QLibrary::tr(".qtmetadata section is too small"), errorString);
+ const bool binaryIsEncrypted = isEncrypted(header);
qsizetype pos = reinterpret_cast<const char *>(header) - m_s + sect[j].offset;
- if (IncludeValidityChecks) {
+
+ // We can not read the section data of encrypted libraries until they
+ // have been dlopened(), so skip validity check if that's the case.
+ if (IncludeValidityChecks && !binaryIsEncrypted) {
QByteArrayView expectedMagic = QByteArrayView::fromArray(QPluginMetaData::MagicString);
QByteArrayView actualMagic = QByteArrayView(m_s + pos, expectedMagic.size());
if (expectedMagic != actualMagic)
@@ -175,7 +196,7 @@ QLibraryScanResult QMachOParser::parse(const char *m_s, ulong fdlen, QString *e
}
pos += sizeof(QPluginMetaData::MagicString);
- return { pos, qsizetype(sect[j].size - sizeof(QPluginMetaData::MagicString)) };
+ return { pos, qsizetype(sect[j].size - sizeof(QPluginMetaData::MagicString)), binaryIsEncrypted };
}
}
diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h
index 5ac3ed9241..017064e747 100644
--- a/src/corelib/plugin/qplugin.h
+++ b/src/corelib/plugin/qplugin.h
@@ -9,6 +9,8 @@
#include <QtCore/qpointer.h>
#include <QtCore/qjsonobject.h>
+#include <QtCore/q20algorithm.h>
+
QT_BEGIN_NAMESPACE
// Used up to Qt 6.2
@@ -38,10 +40,8 @@ struct QPluginMetaData
template <size_t OSize, typename OO, size_t ISize, typename II>
static constexpr void copy(OO (&out)[OSize], II (&in)[ISize])
{
- // std::copy is not constexpr until C++20
static_assert(OSize <= ISize, "Output would not be fully initialized");
- for (size_t i = 0; i < OSize; ++i)
- out[i] = in[i];
+ q20::copy_n(in, OSize, out);
}
static constexpr quint8 archRequirements()
diff --git a/src/corelib/plugin/qplugin.qdoc b/src/corelib/plugin/qplugin.qdoc
index ed023a75c9..dd4aa5f4b0 100644
--- a/src/corelib/plugin/qplugin.qdoc
+++ b/src/corelib/plugin/qplugin.qdoc
@@ -82,11 +82,9 @@
\snippet code/doc_src_qplugin.cpp 2
Static plugins must also be included by the linker when your
- application is built. For Qt's predefined plugins,
- you can use the \c QTPLUGIN to add
- the required plugins to your build. For example:
+ application is built. See \l{Static Plugins} for more information
+ on this.
- \snippet code/doc_src_qplugin.pro 3
- \sa {Static Plugins}, {How to Create Qt Plugins}, {qmake-getting-started}{Getting Started with qmake}
+ \sa {Static Plugins}, {How to Create Qt Plugins}
*/
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp
index e86d4ccec8..599256783e 100644
--- a/src/corelib/plugin/qpluginloader.cpp
+++ b/src/corelib/plugin/qpluginloader.cpp
@@ -246,9 +246,9 @@ static QString locatePlugin(const QString& fileName)
paths = QCoreApplication::libraryPaths();
}
- for (const QString &path : qAsConst(paths)) {
- for (const QString &prefix : qAsConst(prefixes)) {
- for (const QString &suffix : qAsConst(suffixes)) {
+ for (const QString &path : std::as_const(paths)) {
+ for (const QString &prefix : std::as_const(prefixes)) {
+ for (const QString &suffix : std::as_const(suffixes)) {
#ifdef Q_OS_ANDROID
{
QString pluginPath = basePath + prefix + baseName + suffix;
diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp
index e9d31b4cc3..2d9cb71112 100644
--- a/src/corelib/serialization/qcborarray.cpp
+++ b/src/corelib/serialization/qcborarray.cpp
@@ -13,6 +13,7 @@ using namespace QtCbor;
\class QCborArray
\inmodule QtCore
\ingroup cbor
+ \ingroup qtserialization
\reentrant
\since 5.12
@@ -30,7 +31,8 @@ using namespace QtCbor;
from those two, though there may be loss of information in some
conversions.
- \sa QCborValue, QCborMap, QJsonArray, QList
+ \sa QCborValue, QCborMap, QJsonArray, QList, {Cbordump Example},
+ {Convert Example}, {JSON Save Game Example}
*/
/*!
diff --git a/src/corelib/serialization/qcborcommon.cpp b/src/corelib/serialization/qcborcommon.cpp
index 648ca59d8b..66d6dcd685 100644
--- a/src/corelib/serialization/qcborcommon.cpp
+++ b/src/corelib/serialization/qcborcommon.cpp
@@ -17,6 +17,7 @@ QT_IMPL_METATYPE_EXTERN(QCborTag)
/*!
\headerfile <QtCborCommon>
\inmodule QtCore
+ \ingroup qtserialization
\brief The <QtCborCommon> header contains definitions common to both the
streaming classes (QCborStreamReader and QCborStreamWriter) and to
QCborValue.
@@ -179,6 +180,7 @@ QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st)
validating a CBOR stream.
\sa QCborStreamReader, QCborValue, QCborParserError
+ \sa {Cbordump Example}, {Convert Example}, {JSON Save Game Example}
*/
/*!
@@ -197,7 +199,7 @@ QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st)
\value UnexpectedBreak The CBOR stream contains a Break where it is not allowed (data is
corrupt and the error is not recoverable).
\value UnknownType The CBOR stream contains an unknown/unparsable Type (data is corrupt
- and the and the error is not recoverable).
+ and the error is not recoverable).
\value IllegalType The CBOR stream contains a known type in a position it is not allowed
to exist (data is corrupt and the error is not recoverable).
\value IllegalNumber The CBOR stream appears to be encoding a number larger than 64-bit
diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp
index 050565d5ae..3eda1e82cf 100644
--- a/src/corelib/serialization/qcbormap.cpp
+++ b/src/corelib/serialization/qcbormap.cpp
@@ -12,6 +12,7 @@ using namespace QtCbor;
\class QCborMap
\inmodule QtCore
\ingroup cbor
+ \ingroup qtserialization
\reentrant
\since 5.12
@@ -46,7 +47,8 @@ using namespace QtCbor;
stringified using a one-way method that the conversion back to QCborMap
will not undo.
- \sa QCborArray, QCborValue, QJsonDocument, QVariantMap
+ \sa QCborArray, QCborValue, QJsonDocument, QVariantMap, {Cbordump Example}
+ \sa {Convert Example}, {JSON Save Game Example}
*/
/*!
diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp
index 10b3eb2d45..c0a32c303b 100644
--- a/src/corelib/serialization/qcborstreamreader.cpp
+++ b/src/corelib/serialization/qcborstreamreader.cpp
@@ -62,6 +62,7 @@ static_assert(int(QCborStreamReader::Invalid) == CborInvalidType);
\class QCborStreamReader
\inmodule QtCore
\ingroup cbor
+ \ingroup qtserialization
\reentrant
\since 5.12
@@ -151,7 +152,8 @@ static_assert(int(QCborStreamReader::Invalid) == CborInvalidType);
parsing from a QByteArray, or reparse(), if it is instead reading directly
a the QIDOevice that now has more data available (see setDevice()).
- \sa QCborStreamWriter, QCborValue, QXmlStreamReader
+ \sa QCborStreamWriter, QCborValue, QXmlStreamReader, {Cbordump Example}
+ \sa {Convert Example}, {JSON Save Game Example}
*/
/*!
@@ -969,7 +971,7 @@ QCborStreamReader::Type QCborStreamReader::parentContainerType() const
{
if (d->containerStack.isEmpty())
return Invalid;
- return Type(cbor_value_get_type(&qAsConst(d->containerStack).top()));
+ return Type(cbor_value_get_type(&std::as_const(d->containerStack).top()));
}
/*!
@@ -1308,7 +1310,7 @@ QCborStreamReader::StringResult<QString> QCborStreamReader::_readString_helper()
if (r.status == Error) {
result.data.clear();
} else {
- Q_ASSERT(r.data == result.data.length());
+ Q_ASSERT(r.data == result.data.size());
if (r.status == EndOfString && lastError() == QCborError::NoError)
preparse();
}
@@ -1340,7 +1342,7 @@ QCborStreamReader::StringResult<QByteArray> QCborStreamReader::_readByteArray_he
if (r.status == Error) {
result.data.clear();
} else {
- Q_ASSERT(r.data == result.data.length());
+ Q_ASSERT(r.data == result.data.size());
if (r.status == EndOfString && lastError() == QCborError::NoError)
preparse();
}
diff --git a/src/corelib/serialization/qcborstreamwriter.cpp b/src/corelib/serialization/qcborstreamwriter.cpp
index 9f7e30e8cb..696f55b0b0 100644
--- a/src/corelib/serialization/qcborstreamwriter.cpp
+++ b/src/corelib/serialization/qcborstreamwriter.cpp
@@ -45,6 +45,7 @@ Q_DECLARE_TYPEINFO(CborEncoder, Q_PRIMITIVE_TYPE);
\class QCborStreamWriter
\inmodule QtCore
\ingroup cbor
+ \ingroup qtserialization
\reentrant
\since 5.12
@@ -175,6 +176,7 @@ Q_DECLARE_TYPEINFO(CborEncoder, Q_PRIMITIVE_TYPE);
\endlist
\sa QCborStreamReader, QCborValue, QXmlStreamWriter
+ \sa {Cbordump Example}, {Convert Example}, {JSON Save Game Example}
*/
class QCborStreamWriterPrivate
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp
index 056e8c07b6..0d11aa86dc 100644
--- a/src/corelib/serialization/qcborvalue.cpp
+++ b/src/corelib/serialization/qcborvalue.cpp
@@ -44,6 +44,7 @@ Q_DECL_UNUSED static constexpr quint64 MaximumPreallocatedElementCount =
\class QCborValue
\inmodule QtCore
\ingroup cbor
+ \ingroup qtserialization
\reentrant
\since 5.12
@@ -189,7 +190,8 @@ Q_DECL_UNUSED static constexpr quint64 MaximumPreallocatedElementCount =
aspects, its API is identical to QCborValue.
\sa QCborArray, QCborMap, QCborStreamReader, QCborStreamWriter
- QJsonValue, QJsonDocument
+ \sa QJsonValue, QJsonDocument, {Cbordump Example}, {Convert Example}
+ \sa {JSON Save Game Example}
*/
/*!
@@ -943,7 +945,7 @@ QCborContainerPrivate *QCborContainerPrivate::clone(QCborContainerPrivate *d, qs
d = u.take();
d->ref.storeRelaxed(0);
- for (auto &e : qAsConst(d->elements)) {
+ for (auto &e : std::as_const(d->elements)) {
if (e.flags & Element::IsContainer)
e.container->ref.ref();
}
diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h
index a83a36a3d8..63d0f11a95 100644
--- a/src/corelib/serialization/qcborvalue.h
+++ b/src/corelib/serialization/qcborvalue.h
@@ -545,13 +545,13 @@ public:
#if QT_CONFIG(cborstreamwriter)
using QCborValueConstRef::toCbor;
QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
- { return qAsConst(*this).toCbor(opt); }
+ { return std::as_const(*this).toCbor(opt); }
void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
#endif
using QCborValueConstRef::toDiagnosticNotation;
QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
- { return qAsConst(*this).toDiagnosticNotation(opt); }
+ { return std::as_const(*this).toDiagnosticNotation(opt); }
private:
static QCborValue concrete(QCborValueRef that) noexcept;
diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp
index 59a2a4c53f..05691885a4 100644
--- a/src/corelib/serialization/qdatastream.cpp
+++ b/src/corelib/serialization/qdatastream.cpp
@@ -18,6 +18,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QDataStream
\inmodule QtCore
+ \ingroup qtserialization
\reentrant
\brief The QDataStream class provides serialization of binary data
to a QIODevice.
diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp
index 167b6a3a77..f3b1f671a6 100644
--- a/src/corelib/serialization/qjsonarray.cpp
+++ b/src/corelib/serialization/qjsonarray.cpp
@@ -22,6 +22,7 @@ QT_BEGIN_NAMESPACE
\inmodule QtCore
\ingroup json
\ingroup shared
+ \ingroup qtserialization
\reentrant
\since 5.0
@@ -339,7 +340,7 @@ void QJsonArray::append(const QJsonValue &value)
*/
void QJsonArray::removeAt(qsizetype i)
{
- if (!a || i < 0 || i >= a->elements.length())
+ if (!a || i < 0 || i >= a->elements.size())
return;
detach();
a->removeAt(i);
@@ -375,7 +376,7 @@ void QJsonArray::removeAt(qsizetype i)
*/
QJsonValue QJsonArray::takeAt(qsizetype i)
{
- if (!a || i < 0 || i >= a->elements.length())
+ if (!a || i < 0 || i >= a->elements.size())
return QJsonValue(QJsonValue::Undefined);
detach();
@@ -394,11 +395,11 @@ QJsonValue QJsonArray::takeAt(qsizetype i)
void QJsonArray::insert(qsizetype i, const QJsonValue &value)
{
if (a)
- detach(a->elements.length() + 1);
+ detach(a->elements.size() + 1);
else
a = new QCborContainerPrivate;
- Q_ASSERT (i >= 0 && i <= a->elements.length());
+ Q_ASSERT (i >= 0 && i <= a->elements.size());
a->insertAt(i, value.type() == QJsonValue::Undefined ? QCborValue(nullptr)
: QCborValue::fromJsonValue(value));
}
@@ -429,7 +430,7 @@ void QJsonArray::insert(qsizetype i, const QJsonValue &value)
*/
void QJsonArray::replace(qsizetype i, const QJsonValue &value)
{
- Q_ASSERT (a && i >= 0 && i < a->elements.length());
+ Q_ASSERT (a && i >= 0 && i < a->elements.size());
detach();
a->replaceAt(i, QCborValue::fromJsonValue(value));
}
@@ -463,7 +464,7 @@ bool QJsonArray::contains(const QJsonValue &value) const
*/
QJsonValueRef QJsonArray::operator [](qsizetype i)
{
- Q_ASSERT(a && i >= 0 && i < a->elements.length());
+ Q_ASSERT(a && i >= 0 && i < a->elements.size());
return QJsonValueRef(this, i);
}
@@ -486,13 +487,13 @@ bool QJsonArray::operator==(const QJsonArray &other) const
return true;
if (!a)
- return !other.a->elements.length();
+ return !other.a->elements.size();
if (!other.a)
- return !a->elements.length();
- if (a->elements.length() != other.a->elements.length())
+ return !a->elements.size();
+ if (a->elements.size() != other.a->elements.size())
return false;
- for (qsizetype i = 0; i < a->elements.length(); ++i) {
+ for (qsizetype i = 0; i < a->elements.size(); ++i) {
if (a->valueAt(i) != other.a->valueAt(i))
return false;
}
diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp
index 814033610f..446cfcd303 100644
--- a/src/corelib/serialization/qjsondocument.cpp
+++ b/src/corelib/serialization/qjsondocument.cpp
@@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE
\inmodule QtCore
\ingroup json
\ingroup shared
+ \ingroup qtserialization
\reentrant
\since 5.0
@@ -280,7 +281,7 @@ QByteArray QJsonDocument::toJson(JsonFormat format) const
*/
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error)
{
- QJsonPrivate::Parser parser(json.constData(), json.length());
+ QJsonPrivate::Parser parser(json.constData(), json.size());
QJsonDocument result;
const QCborValue val = parser.parse(error);
if (val.isArray() || val.isMap()) {
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index 0a5bafd1cb..589bbfeeba 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -25,6 +25,7 @@ QT_BEGIN_NAMESPACE
\inmodule QtCore
\ingroup json
\ingroup shared
+ \ingroup qtserialization
\reentrant
\since 5.0
@@ -236,8 +237,8 @@ QStringList QJsonObject::keys() const
{
QStringList keys;
if (o) {
- keys.reserve(o->elements.length() / 2);
- for (qsizetype i = 0, end = o->elements.length(); i < end; i += 2)
+ keys.reserve(o->elements.size() / 2);
+ for (qsizetype i = 0, end = o->elements.size(); i < end; i += 2)
keys.append(o->stringAt(i));
}
return keys;
@@ -248,7 +249,7 @@ QStringList QJsonObject::keys() const
*/
qsizetype QJsonObject::size() const
{
- return o ? o->elements.length() / 2 : 0;
+ return o ? o->elements.size() / 2 : 0;
}
/*!
@@ -400,7 +401,7 @@ QJsonValueRef QJsonObject::atImpl(T key)
bool keyExists = false;
auto index = indexOf(o, key, &keyExists);
if (!keyExists) {
- detach(o->elements.length() / 2 + 1);
+ detach(o->elements.size() / 2 + 1);
o->insertAt(index, key);
o->insertAt(index + 1, QCborValue::fromJsonValue(QJsonValue()));
}
@@ -466,7 +467,7 @@ template <typename T>
QJsonObject::iterator QJsonObject::insertAt(qsizetype pos, T key, const QJsonValue &value, bool keyExists)
{
if (o)
- detach(o->elements.length() / 2 + (keyExists ? 0 : 1));
+ detach(o->elements.size() / 2 + (keyExists ? 0 : 1));
else
o = new QCborContainerPrivate;
@@ -627,13 +628,13 @@ bool QJsonObject::operator==(const QJsonObject &other) const
return true;
if (!o)
- return !other.o->elements.length();
+ return !other.o->elements.size();
if (!other.o)
- return !o->elements.length();
- if (o->elements.length() != other.o->elements.length())
+ return !o->elements.size();
+ if (o->elements.size() != other.o->elements.size())
return false;
- for (qsizetype i = 0, end = o->elements.length(); i < end; ++i) {
+ for (qsizetype i = 0, end = o->elements.size(); i < end; ++i) {
if (o->valueAt(i) != other.o->valueAt(i))
return false;
}
@@ -1360,7 +1361,7 @@ bool QJsonObject::detach(qsizetype reserve)
{
if (!o)
return true;
- o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.length());
+ o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.size());
return o;
}
@@ -1370,7 +1371,7 @@ bool QJsonObject::detach(qsizetype reserve)
*/
QString QJsonObject::keyAt(qsizetype i) const
{
- Q_ASSERT(o && i >= 0 && i * 2 < o->elements.length());
+ Q_ASSERT(o && i >= 0 && i * 2 < o->elements.size());
return o->stringAt(i * 2);
}
@@ -1379,7 +1380,7 @@ QString QJsonObject::keyAt(qsizetype i) const
*/
QJsonValue QJsonObject::valueAt(qsizetype i) const
{
- if (!o || i < 0 || 2 * i + 1 >= o->elements.length())
+ if (!o || i < 0 || 2 * i + 1 >= o->elements.size())
return QJsonValue(QJsonValue::Undefined);
return QJsonPrivate::Value::fromTrustedCbor(o->valueAt(2 * i + 1));
}
@@ -1389,7 +1390,7 @@ QJsonValue QJsonObject::valueAt(qsizetype i) const
*/
void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val)
{
- Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length());
+ Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.size());
detach();
if (val.isUndefined()) {
o->removeAt(2 * i + 1);
diff --git a/src/corelib/serialization/qjsonparser.cpp b/src/corelib/serialization/qjsonparser.cpp
index 294a65fa86..b11ae3a9d2 100644
--- a/src/corelib/serialization/qjsonparser.cpp
+++ b/src/corelib/serialization/qjsonparser.cpp
@@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE
\inmodule QtCore
\ingroup json
\ingroup shared
+ \ingroup qtserialization
\reentrant
\since 5.0
@@ -552,7 +553,7 @@ bool Parser::parseArray()
}
}
- DEBUG << "size =" << (container ? container->elements.length() : 0);
+ DEBUG << "size =" << (container ? container->elements.size() : 0);
END;
--nestingLevel;
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp
index ef07dcdc3b..8b5f3cd243 100644
--- a/src/corelib/serialization/qjsonvalue.cpp
+++ b/src/corelib/serialization/qjsonvalue.cpp
@@ -53,6 +53,7 @@ static QJsonValue::Type convertFromCborType(QCborValue::Type type) noexcept
\inmodule QtCore
\ingroup json
\ingroup shared
+ \ingroup qtserialization
\reentrant
\since 5.0
diff --git a/src/corelib/serialization/qjsonwriter.cpp b/src/corelib/serialization/qjsonwriter.cpp
index f4ec110684..b0e6ef1d0c 100644
--- a/src/corelib/serialization/qjsonwriter.cpp
+++ b/src/corelib/serialization/qjsonwriter.cpp
@@ -25,10 +25,10 @@ static inline uchar hexdig(uint u)
static QByteArray escapedString(const QString &s)
{
// give it a minimum size to ensure the resize() below always adds enough space
- QByteArray ba(qMax(s.length(), 16), Qt::Uninitialized);
+ QByteArray ba(qMax(s.size(), 16), Qt::Uninitialized);
uchar *cursor = reinterpret_cast<uchar *>(const_cast<char *>(ba.constData()));
- const uchar *ba_end = cursor + ba.length();
+ const uchar *ba_end = cursor + ba.size();
const char16_t *src = reinterpret_cast<const char16_t *>(s.constBegin());
const char16_t *const end = reinterpret_cast<const char16_t *>(s.constEnd());
@@ -38,7 +38,7 @@ static QByteArray escapedString(const QString &s)
int pos = cursor - (const uchar *)ba.constData();
ba.resize(ba.size()*2);
cursor = (uchar *)ba.data() + pos;
- ba_end = (const uchar *)ba.constData() + ba.length();
+ ba_end = (const uchar *)ba.constData() + ba.size();
}
char16_t u = *src++;
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp
index 5b0ab7fb47..83e97c834d 100644
--- a/src/corelib/serialization/qtextstream.cpp
+++ b/src/corelib/serialization/qtextstream.cpp
@@ -14,6 +14,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
\ingroup io
\ingroup string-processing
+ \ingroup qtserialization
\reentrant
QTextStream can operate on a QIODevice, a QByteArray or a
@@ -1399,7 +1400,8 @@ QTextStream::RealNumberNotation QTextStream::realNumberNotation() const
/*!
Sets the precision of real numbers to \a precision. This value
describes the number of fraction digits QTextStream should
- write when generating real numbers.
+ write when generating real numbers (FixedNotation, ScientificNotation), or
+ the maximum number of significant digits (SmartNotation).
The precision cannot be a negative value. The default value is 6.
@@ -1418,7 +1420,9 @@ void QTextStream::setRealNumberPrecision(int precision)
/*!
Returns the current real number precision, or the number of fraction
- digits QTextStream will write when generating real numbers.
+ digits QTextStream will write when generating real numbers
+ (FixedNotation, ScientificNotation), or the maximum number of significant
+ digits (SmartNotation).
\sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase()
*/
@@ -2497,7 +2501,7 @@ QTextStream &QTextStream::operator<<(const QByteArray &array)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString::fromUtf8(array.constData(), array.length()));
+ d->putString(QString::fromUtf8(array.constData(), array.size()));
return *this;
}
@@ -2941,7 +2945,7 @@ void QTextStream::setEncoding(QStringConverter::Encoding encoding)
d->encoding = encoding;
d->toUtf16 = QStringDecoder(d->encoding);
- bool generateBOM = d->hasWrittenData && d->generateBOM;
+ bool generateBOM = !d->hasWrittenData && d->generateBOM;
d->fromUtf16 = QStringEncoder(d->encoding,
generateBOM ? QStringEncoder::Flag::WriteBom : QStringEncoder::Flag::Default);
diff --git a/src/corelib/serialization/qtextstream_p.h b/src/corelib/serialization/qtextstream_p.h
index c5967845f9..909b75d0de 100644
--- a/src/corelib/serialization/qtextstream_p.h
+++ b/src/corelib/serialization/qtextstream_p.h
@@ -139,14 +139,14 @@ public:
NumberParsingStatus getNumber(qulonglong *l);
bool getReal(double *f);
- inline void write(QStringView data) { write(data.begin(), data.length()); }
+ inline void write(QStringView data) { write(data.begin(), data.size()); }
inline void write(QChar ch);
void write(const QChar *data, qsizetype len);
void write(QLatin1StringView data);
void writePadding(qsizetype len);
inline void putString(QStringView string, bool number = false)
{
- putString(string.constData(), string.length(), number);
+ putString(string.constData(), string.size(), number);
}
void putString(const QChar *data, qsizetype len, bool number = false);
void putString(QLatin1StringView data, bool number = false);
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp
index a6a2bc41af..70e65df995 100644
--- a/src/corelib/serialization/qxmlstream.cpp
+++ b/src/corelib/serialization/qxmlstream.cpp
@@ -229,6 +229,8 @@ QXmlStreamEntityResolver *QXmlStreamReader::entityResolver() const
\ingroup xml-tools
+ \ingroup qtserialization
+
QXmlStreamReader provides a simple streaming API to parse well-formed
XML. It is an alternative to first loading the complete XML into a
DOM tree (see \l QDomDocument). QXmlStreamReader reads data either
@@ -2735,6 +2737,7 @@ QStringView QXmlStreamReader::documentEncoding() const
simple streaming API.
\ingroup xml-tools
+ \ingroup qtserialization
QXmlStreamWriter is the counterpart to QXmlStreamReader for writing
XML. Like its related class, it operates on a QIODevice specified
@@ -3035,7 +3038,7 @@ void QXmlStreamWriterPrivate::indent(int level)
{
write("\n");
for (int i = level; i > 0; --i)
- write(autoFormattingIndent.constData(), autoFormattingIndent.length());
+ write(autoFormattingIndent.constData(), autoFormattingIndent.size());
}
diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h
index 8e523f9c67..1fd69a2c1f 100644
--- a/src/corelib/serialization/qxmlstream_p.h
+++ b/src/corelib/serialization/qxmlstream_p.h
@@ -42,7 +42,7 @@ public:
{
}
XmlStringRef(const QString *string)
- : XmlStringRef(string, 0, string->length())
+ : XmlStringRef(string, 0, string->size())
{
}
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index 0cd97fd54e..b1af305d0d 100644
--- a/src/corelib/text/qanystringview.h
+++ b/src/corelib/text/qanystringview.h
@@ -51,15 +51,18 @@ private:
static constexpr bool isAsciiOnlyCharsAtCompileTime(Char *str, qsizetype sz) noexcept
{
// do not perform check if not at compile time
-#if defined(__cpp_lib_is_constant_evaluated)
+#if !(defined(__cpp_lib_is_constant_evaluated) || defined(Q_CC_GNU))
+ Q_UNUSED(str);
+ Q_UNUSED(sz);
+ return false;
+#else
+# if defined(__cpp_lib_is_constant_evaluated)
if (!std::is_constant_evaluated())
return false;
-#elif defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
+# elif defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
if (!str || !__builtin_constant_p(*str))
return false;
-#else
- return false;
-#endif
+# endif
if constexpr (sizeof(Char) != sizeof(char)) {
Q_UNUSED(str);
Q_UNUSED(sz);
@@ -69,8 +72,9 @@ private:
if (uchar(str[i]) > 0x7f)
return false;
}
+ return true;
}
- return true;
+#endif
}
template<typename Char>
diff --git a/src/corelib/text/qanystringview.qdoc b/src/corelib/text/qanystringview.qdoc
index b70f7b028b..796202e2e1 100644
--- a/src/corelib/text/qanystringview.qdoc
+++ b/src/corelib/text/qanystringview.qdoc
@@ -17,9 +17,11 @@
Unlike QStringView and QUtf8StringView, QAnyStringView can hold
strings of any of the following encodings: UTF-8, UTF-16, and
- Latin-1. The latter is supported to keep old source working
- efficiently. It is expected that by Qt 7, the Latin-1 support will
- be removed.
+ Latin-1. The latter is supported because Latin-1, unlike UTF-8,
+ can be efficiently compared to UTF-16 data: a length mismatch
+ already means the strings cannot be equal. This is not true for
+ UTF-8/UTF-16 comparisons, because UTF-8 is a variable-length
+ encoding.
The string may be represented as an array (or an array-compatible
data-structure such as QString, std::basic_string, etc.) of \c
@@ -36,7 +38,7 @@
When used as an interface type, QAnyStringView allows a single
function to accept a wide variety of string data sources. One
function accepting QAnyStringView thus replaces five function
- overloads (taking QString, \c{(const QChar*, int)},
+ overloads (taking QString, \c{(const QChar*, qsizetype)},
QUtf8StringView, QLatin1StringView (but see above), and QChar), while
at the same time enabling even more string data sources to be
passed to the function, such as \c{u8"Hello World"}, a \c char8_t
@@ -45,6 +47,11 @@
Like elsewhere in Qt, QAnyStringView assumes \c char data is encoded
in UTF-8, unless it is presented as a QLatin1StringView.
+ Since Qt 6.4, however, UTF-8 string literals that are pure US-ASCII are
+ automatically stored as Latin-1. This is a compile-time check with no
+ runtime overhead. The feature requires compiling in C++20, or with a recent
+ GCC.
+
QAnyStringViews should be passed by value, not by reference-to-const:
\snippet code/src_corelib_text_qanystringview.cpp 0
@@ -297,7 +304,7 @@
*/
/*!
- \fn int QAnyStringView::length() const
+ \fn QAnyStringView::length() const
Same as size().
@@ -332,6 +339,72 @@
\sa front(), {Sizes and Sub-Strings}
*/
+/*! \fn template <typename Visitor> decltype(auto) QAnyStringView::visit(Visitor &&v) const
+
+ Calls \a v with either a QUtf8StringView, QLatin1String, or QStringView, depending
+ on the encoding of the string data this string-view references.
+
+ This is how most functions taking QAnyStringView fork off into per-encoding
+ functions:
+
+ \code
+ void processImpl(QLatin1String s) { ~~~ }
+ void processImpl(QUtf8StringView s) { ~~~ }
+ void processImpl(QStringView s) { ~~~ }
+
+ void process(QAnyStringView s)
+ {
+ s.visit([](auto s) { processImpl(s); });
+ }
+ \endcode
+
+ Here, we're reusing the same name, \c s, for both the QAnyStringView
+ object, as well as the lambda's parameter. This is idiomatic code and helps
+ track the identity of the objects through visit() calls, for example in more
+ complex situations such as
+
+ \code
+ bool equal(QAnyStringView lhs, QAnyStringView rhs)
+ {
+ // assuming operator==(QAnyStringView, QAnyStringView) didn't, yet, exist:
+ return lhs.visit([rhs](auto lhs) {
+ rhs.visit([lhs](auto rhs) {
+ return lhs == rhs;
+ });
+ });
+ }
+ \endcode
+
+ visit() requires that all lambda instantiations have the same return type.
+ If they differ, you get a compile error, even if there is a common type. To
+ fix, you can use explicit return types on the lambda, or cast in the return
+ statements:
+
+ \code
+ // wrong:
+ QAnyStringView firstHalf(QAnyStringView input)
+ {
+ return input.visit([](auto input) { // ERROR: lambdas return different types
+ return input.sliced(0, input.size() / 2);
+ });
+ }
+ // correct:
+ QAnyStringView firstHalf(QAnyStringView input)
+ {
+ return input.visit([](auto input) -> QAnyStringView { // OK, explicit return type
+ return input.sliced(0, input.size() / 2);
+ });
+ }
+ // also correct:
+ QAnyStringView firstHalf(QAnyStringView input)
+ {
+ return input.visit([](auto input) {
+ return QAnyStringView(input.sliced(0, input.size() / 2)); // OK, cast to common type
+ });
+ }
+ \endcode
+*/
+
/*!
\fn QAnyStringView::compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs)
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index f728877e4a..ba6e79543a 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -22,6 +22,7 @@
#ifndef QT_NO_COMPRESS
#include <zconf.h>
#include <zlib.h>
+#include <qxpfunctional.h>
#endif
#include <ctype.h>
#include <limits.h>
@@ -110,23 +111,29 @@ char *qstrcpy(char *dst, const char *src)
A safe \c strncpy() function.
Copies at most \a len bytes from \a src (stopping at \a len or the
- terminating '\\0' whichever comes first) into \a dst and returns a
- pointer to \a dst. Guarantees that \a dst is '\\0'-terminated. If
- \a src or \a dst is \nullptr, returns \nullptr immediately.
+ terminating '\\0' whichever comes first) into \a dst. Guarantees that \a
+ dst is '\\0'-terminated, except when \a dst is \nullptr or \a len is 0. If
+ \a src is \nullptr, returns \nullptr, otherwise returns \a dst.
This function assumes that \a dst is at least \a len characters
long.
\note If \a dst and \a src overlap, the behavior is undefined.
+ \note Unlike strncpy(), this function does \e not write '\\0' to all \a
+ len bytes of \a dst, but stops after the terminating '\\0'. In this sense,
+ it's similar to C11's strncpy_s().
+
\sa qstrcpy()
*/
char *qstrncpy(char *dst, const char *src, size_t len)
{
- if (!src || !dst)
- return nullptr;
- if (len > 0) {
+ if (dst && len > 0) {
+ if (!src) {
+ *dst = '\0';
+ return nullptr;
+ }
#ifdef Q_CC_MSVC
strncpy_s(dst, len, src, len - 1);
#else
@@ -134,7 +141,7 @@ char *qstrncpy(char *dst, const char *src, size_t len)
#endif
dst[len-1] = '\0';
}
- return dst;
+ return src ? dst : nullptr;
}
/*! \fn size_t qstrlen(const char *str)
@@ -508,7 +515,9 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard)
\sa qUncompress(const QByteArray &data)
*/
-/*! \relates QByteArray
+/*!
+ \fn QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel)
+ \relates QByteArray
\overload
@@ -517,44 +526,197 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard)
*/
#ifndef QT_NO_COMPRESS
+using CompressSizeHint_t = quint32; // 32-bit BE, historically
+
+enum class ZLibOp : bool { Compression, Decompression };
+
+Q_DECL_COLD_FUNCTION
+static const char *zlibOpAsString(ZLibOp op)
+{
+ switch (op) {
+ case ZLibOp::Compression: return "qCompress";
+ case ZLibOp::Decompression: return "qUncompress";
+ }
+ Q_UNREACHABLE();
+ return nullptr;
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray zlibError(ZLibOp op, const char *what)
+{
+ qWarning("%s: %s", zlibOpAsString(op), what);
+ return QByteArray();
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray dataIsNull(ZLibOp op)
+{
+ return zlibError(op, "Data is null");
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray lengthIsNegative(ZLibOp op)
+{
+ return zlibError(op, "Input length is negative");
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray tooMuchData(ZLibOp op)
+{
+ return zlibError(op, "Not enough memory");
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray invalidCompressedData()
+{
+ return zlibError(ZLibOp::Decompression, "Input data is corrupted");
+}
+
+Q_DECL_COLD_FUNCTION
+static QByteArray unexpectedZlibError(ZLibOp op, int err, const char *msg)
+{
+ qWarning("%s unexpected zlib error: %s (%d)",
+ zlibOpAsString(op),
+ msg ? msg : "",
+ err);
+ return QByteArray();
+}
+
+static QByteArray xxflate(ZLibOp op, QArrayDataPointer<char> out, QByteArrayView input,
+ qxp::function_ref<int(z_stream *) const> init,
+ qxp::function_ref<int(z_stream *, size_t) const> processChunk,
+ qxp::function_ref<void(z_stream *) const> deinit)
+{
+ if (out.data() == nullptr) // allocation failed
+ return tooMuchData(op);
+ qsizetype capacity = out.allocatedCapacity();
+
+ const auto initalSize = out.size;
+
+ z_stream zs = {};
+ zs.next_in = reinterpret_cast<uchar *>(const_cast<char *>(input.data())); // 1980s C API...
+ if (const int err = init(&zs); err != Z_OK)
+ return unexpectedZlibError(op, err, zs.msg);
+ const auto sg = qScopeGuard([&] { deinit(&zs); });
+
+ using ZlibChunkSize_t = decltype(zs.avail_in);
+ static_assert(!std::is_signed_v<ZlibChunkSize_t>);
+ static_assert(std::is_same_v<ZlibChunkSize_t, decltype(zs.avail_out)>);
+ constexpr auto MaxChunkSize = std::numeric_limits<ZlibChunkSize_t>::max();
+ [[maybe_unused]]
+ constexpr auto MaxStatisticsSize = std::numeric_limits<decltype(zs.total_out)>::max();
+
+ size_t inputLeft = size_t(input.size());
+
+ int res;
+ do {
+ Q_ASSERT(out.freeSpaceAtBegin() == 0); // ensure prepend optimization stays out of the way
+ Q_ASSERT(capacity == out.allocatedCapacity());
+
+ if (zs.avail_out == 0) {
+ Q_ASSERT(size_t(out.size) - initalSize > MaxStatisticsSize || // total_out overflow
+ size_t(out.size) - initalSize == zs.total_out);
+ Q_ASSERT(out.size <= capacity);
+
+ qsizetype avail_out = capacity - out.size;
+ if (avail_out == 0) {
+ out->reallocateAndGrow(QArrayData::GrowsAtEnd, 1); // grow to next natural capacity
+ if (out.data() == nullptr) // reallocation failed
+ return tooMuchData(op);
+ capacity = out.allocatedCapacity();
+ avail_out = capacity - out.size;
+ }
+ zs.next_out = reinterpret_cast<uchar *>(out.data()) + out.size;
+ zs.avail_out = size_t(avail_out) > size_t(MaxChunkSize) ? MaxChunkSize
+ : ZlibChunkSize_t(avail_out);
+ out.size += zs.avail_out;
+
+ Q_ASSERT(zs.avail_out > 0);
+ }
+
+ if (zs.avail_in == 0) {
+ // zs.next_in is kept up-to-date by processChunk(), so nothing to do
+ zs.avail_in = inputLeft > MaxChunkSize ? MaxChunkSize : ZlibChunkSize_t(inputLeft);
+ inputLeft -= zs.avail_in;
+ }
+
+ res = processChunk(&zs, inputLeft);
+ } while (res == Z_OK);
+
+ switch (res) {
+ case Z_STREAM_END:
+ out.size -= zs.avail_out;
+ Q_ASSERT(size_t(out.size) - initalSize > MaxStatisticsSize || // total_out overflow
+ size_t(out.size) - initalSize == zs.total_out);
+ Q_ASSERT(out.size <= out.allocatedCapacity());
+ out.data()[out.size] = '\0';
+ return QByteArray(std::move(out));
+
+ case Z_MEM_ERROR:
+ return tooMuchData(op);
+
+ case Z_BUF_ERROR:
+ Q_UNREACHABLE(); // cannot happen - we supply a buffer that can hold the result,
+ // or else error out early
+
+ case Z_DATA_ERROR: // can only happen on decompression
+ Q_ASSERT(op == ZLibOp::Decompression);
+ return invalidCompressedData();
+
+ default:
+ return unexpectedZlibError(op, res, zs.msg);
+ }
+}
+
QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel)
{
+ constexpr qsizetype HeaderSize = sizeof(CompressSizeHint_t);
if (nbytes == 0) {
- return QByteArray(4, '\0');
- }
- if (!data) {
- qWarning("qCompress: Data is null");
- return QByteArray();
+ return QByteArray(HeaderSize, '\0');
}
+ if (!data)
+ return dataIsNull(ZLibOp::Compression);
+
+ if (nbytes < 0)
+ return lengthIsNegative(ZLibOp::Compression);
+
if (compressionLevel < -1 || compressionLevel > 9)
compressionLevel = -1;
- ulong len = nbytes + nbytes / 100 + 13;
- QByteArray bazip;
- int res;
- do {
- bazip.resize(len + 4);
- res = ::compress2((uchar*)bazip.data()+4, &len, data, nbytes, compressionLevel);
-
- switch (res) {
- case Z_OK:
- bazip.resize(len + 4);
- bazip[0] = (nbytes & 0xff000000) >> 24;
- bazip[1] = (nbytes & 0x00ff0000) >> 16;
- bazip[2] = (nbytes & 0x0000ff00) >> 8;
- bazip[3] = (nbytes & 0x000000ff);
- break;
- case Z_MEM_ERROR:
- qWarning("qCompress: Z_MEM_ERROR: Not enough memory");
- bazip.resize(0);
- break;
- case Z_BUF_ERROR:
- len *= 2;
- break;
+ QArrayDataPointer out = [&] {
+ constexpr qsizetype SingleAllocLimit = 256 * 1024; // the maximum size for which we use
+ // zlib's compressBound() to guarantee
+ // the output buffer size is sufficient
+ // to hold result
+ qsizetype capacity = HeaderSize;
+ if (nbytes < SingleAllocLimit) {
+ // use maximum size
+ capacity += compressBound(uLong(nbytes)); // cannot overflow (both times)!
+ return QArrayDataPointer{QTypedArrayData<char>::allocate(capacity)};
}
- } while (res == Z_BUF_ERROR);
- return bazip;
+ // for larger buffers, assume it compresses optimally, and
+ // grow geometrically from there:
+ constexpr qsizetype MaxCompressionFactor = 1024; // max theoretical factor is 1032
+ // cf. http://www.zlib.org/zlib_tech.html,
+ // but use a nearby power-of-two (faster)
+ capacity += std::max(qsizetype(compressBound(uLong(SingleAllocLimit))),
+ nbytes / MaxCompressionFactor);
+ return QArrayDataPointer{QTypedArrayData<char>::allocate(capacity, QArrayData::Grow)};
+ }();
+
+ if (out.data() == nullptr) // allocation failed
+ return tooMuchData(ZLibOp::Compression);
+
+ qToBigEndian(qt_saturate<CompressSizeHint_t>(nbytes), out.data());
+ out.size = HeaderSize;
+
+ return xxflate(ZLibOp::Compression, std::move(out), {data, nbytes},
+ [=] (z_stream *zs) { return deflateInit(zs, compressionLevel); },
+ [] (z_stream *zs, size_t inputLeft) {
+ return deflate(zs, inputLeft ? Z_NO_FLUSH : Z_FINISH);
+ },
+ [] (z_stream *zs) { deflateEnd(zs); });
}
#endif
@@ -576,18 +738,21 @@ QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel)
data that was compressed using zlib, you first need to prepend a four
byte header to the byte array containing the data. The header must
contain the expected length (in bytes) of the uncompressed data,
- expressed as an unsigned, big-endian, 32-bit integer.
+ expressed as an unsigned, big-endian, 32-bit integer. This number is
+ just a hint for the initial size of the output buffer size,
+ though. If the indicated size is too small to hold the result, the
+ output buffer size will still be increased until either the output
+ fits or the system runs out of memory. So, despite the 32-bit
+ header, this function, on 64-bit platforms, can produce more than
+ 4GiB of output.
+
+ \note In Qt versions prior to Qt 6.5, more than 2GiB of data
+ worked unreliably; in Qt versions prior to Qt 6.0, not at all.
\sa qCompress()
*/
#ifndef QT_NO_COMPRESS
-static QByteArray invalidCompressedData()
-{
- qWarning("qUncompress: Input data is corrupted");
- return QByteArray();
-}
-
/*! \relates QByteArray
\overload
@@ -597,64 +762,39 @@ static QByteArray invalidCompressedData()
*/
QByteArray qUncompress(const uchar* data, qsizetype nbytes)
{
- if (!data) {
- qWarning("qUncompress: Data is null");
- return QByteArray();
- }
- if (nbytes <= 4) {
- if (nbytes < 4 || (data[0]!=0 || data[1]!=0 || data[2]!=0 || data[3]!=0))
- qWarning("qUncompress: Input data is corrupted");
- return QByteArray();
- }
- size_t expectedSize = size_t((data[0] << 24) | (data[1] << 16) |
- (data[2] << 8) | (data[3] ));
- size_t len = qMax(expectedSize, 1ul);
- const size_t maxPossibleSize = MaxAllocSize - sizeof(QByteArray::Data);
- if (Q_UNLIKELY(len >= maxPossibleSize)) {
- // QByteArray does not support that huge size anyway.
- return invalidCompressedData();
- }
+ if (!data)
+ return dataIsNull(ZLibOp::Decompression);
- QByteArray::DataPointer d(QByteArray::Data::allocate(len));
- if (Q_UNLIKELY(d.data() == nullptr))
+ if (nbytes < 0)
+ return lengthIsNegative(ZLibOp::Decompression);
+
+ constexpr qsizetype HeaderSize = sizeof(CompressSizeHint_t);
+ if (nbytes < HeaderSize)
return invalidCompressedData();
- forever {
- const auto alloc = len;
- int res = ::uncompress((uchar*)d.data(), reinterpret_cast<uLongf*>(&len),
- data+4, nbytes-4);
-
- switch (res) {
- case Z_OK: {
- Q_ASSERT(len <= alloc);
- Q_UNUSED(alloc);
- d.data()[len] = '\0';
- d.size = len;
- return QByteArray(d);
- }
+ const auto expectedSize = qFromBigEndian<CompressSizeHint_t>(data);
+ if (nbytes == HeaderSize) {
+ if (expectedSize != 0)
+ return invalidCompressedData();
+ return QByteArray();
+ }
- case Z_MEM_ERROR:
- qWarning("qUncompress: Z_MEM_ERROR: Not enough memory");
- return QByteArray();
+ constexpr auto MaxDecompressedSize = size_t(MaxByteArraySize);
+ if constexpr (MaxDecompressedSize < std::numeric_limits<CompressSizeHint_t>::max()) {
+ if (expectedSize > MaxDecompressedSize)
+ return tooMuchData(ZLibOp::Decompression);
+ }
- case Z_BUF_ERROR:
- len *= 2;
- if (Q_UNLIKELY(len >= maxPossibleSize)) {
- // QByteArray does not support that huge size anyway.
- return invalidCompressedData();
- } else {
- // grow the block
- d->reallocate(d->allocatedCapacity()*2, QArrayData::Grow);
- if (Q_UNLIKELY(d.data() == nullptr))
- return invalidCompressedData();
- }
- continue;
+ // expectedSize may be truncated, so always use at least nbytes
+ // (larger by at most 1%, according to zlib docs)
+ qsizetype capacity = std::max(qsizetype(expectedSize), // cannot overflow!
+ nbytes);
- case Z_DATA_ERROR:
- qWarning("qUncompress: Z_DATA_ERROR: Input data is corrupted");
- return QByteArray();
- }
- }
+ QArrayDataPointer d(QTypedArrayData<char>::allocate(capacity, QArrayData::KeepSize));
+ return xxflate(ZLibOp::Decompression, std::move(d), {data + HeaderSize, nbytes - HeaderSize},
+ [] (z_stream *zs) { return inflateInit(zs); },
+ [] (z_stream *zs, size_t) { return inflate(zs, Z_NO_FLUSH); },
+ [] (z_stream *zs) { inflateEnd(zs); });
}
#endif
diff --git a/src/corelib/text/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h
index 1ac4356e0a..1de9c23f10 100644
--- a/src/corelib/text/qbytearraymatcher.h
+++ b/src/corelib/text/qbytearraymatcher.h
@@ -6,6 +6,8 @@
#include <QtCore/qbytearray.h>
+#include <QtCore/q20algorithm.h>
+#include <iterator>
#include <limits>
QT_BEGIN_NAMESPACE
@@ -83,31 +85,8 @@ private:
{
const auto uchar_max = (std::numeric_limits<uchar>::max)();
uchar max = n > uchar_max ? uchar_max : uchar(n);
- Skiptable table = {
- // this verbose initialization code aims to avoid some opaque error messages
- // even on powerful compilers such as GCC 5.3. Even though for GCC a loop
- // format can be found that v5.3 groks, it's probably better to go with this
- // for the time being:
- {
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
-
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max,
- }
- };
+ Skiptable table = {};
+ q20::fill(std::begin(table.data), std::end(table.data), max);
pattern += n - max;
while (max--)
table.data[uchar(*pattern++)] = max;
diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc
index f9f4664e39..10cc636fd4 100644
--- a/src/corelib/text/qbytearrayview.qdoc
+++ b/src/corelib/text/qbytearrayview.qdoc
@@ -481,7 +481,7 @@
*/
/*!
- \fn int QByteArrayView::length() const
+ \fn QByteArrayView::length() const
Same as size().
diff --git a/src/corelib/text/qbytedata_p.h b/src/corelib/text/qbytedata_p.h
index 46eee13ccd..699b418465 100644
--- a/src/corelib/text/qbytedata_p.h
+++ b/src/corelib/text/qbytedata_p.h
@@ -241,7 +241,7 @@ public:
// the number of QByteArrays
inline int bufferCount() const
{
- return buffers.length();
+ return buffers.size();
}
inline bool isEmpty() const
@@ -267,12 +267,12 @@ public:
inline bool canReadLine() const {
int i = 0;
- if (i < buffers.length()) {
+ if (i < buffers.size()) {
if (buffers.at(i).indexOf('\n', firstPos) != -1)
return true;
++i;
- for (; i < buffers.length(); i++)
+ for (; i < buffers.size(); i++)
if (buffers.at(i).contains('\n'))
return true;
}
diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp
index 32e293ee9f..a66325f6a5 100644
--- a/src/corelib/text/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -1365,7 +1365,7 @@ static const QChar * QT_FASTCALL decompositionHelper(
{
if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount) {
// compute Hangul syllable decomposition as per UAX #15
- const uint SIndex = ucs4 - Hangul_SBase;
+ const char32_t SIndex = ucs4 - Hangul_SBase;
buffer[0] = QChar(Hangul_LBase + SIndex / Hangul_NCount); // L
buffer[1] = QChar(Hangul_VBase + (SIndex % Hangul_NCount) / Hangul_TCount); // V
buffer[2] = QChar(Hangul_TBase + SIndex % Hangul_TCount); // T
@@ -1815,7 +1815,7 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion
QString &s = *str;
const unsigned short *utf16 = reinterpret_cast<unsigned short *>(s.data());
- const unsigned short *uc = utf16 + s.length();
+ const unsigned short *uc = utf16 + s.size();
while (uc != utf16 + from) {
char32_t ucs4 = *(--uc);
if (QChar(ucs4).isLowSurrogate() && uc != utf16) {
@@ -1861,26 +1861,26 @@ struct UCS2SurrogatePair {
inline bool operator<(const UCS2SurrogatePair &ligature1, const UCS2SurrogatePair &ligature2)
{ return QChar::surrogateToUcs4(ligature1.p1.u1, ligature1.p1.u2) < QChar::surrogateToUcs4(ligature2.p1.u1, ligature2.p1.u2); }
-inline bool operator<(uint u1, const UCS2SurrogatePair &ligature)
+inline bool operator<(char32_t u1, const UCS2SurrogatePair &ligature)
{ return u1 < QChar::surrogateToUcs4(ligature.p1.u1, ligature.p1.u2); }
-inline bool operator<(const UCS2SurrogatePair &ligature, uint u1)
+inline bool operator<(const UCS2SurrogatePair &ligature, char32_t u1)
{ return QChar::surrogateToUcs4(ligature.p1.u1, ligature.p1.u2) < u1; }
-static uint inline ligatureHelper(uint u1, uint u2)
+static char32_t inline ligatureHelper(char32_t u1, char32_t u2)
{
if (u1 >= Hangul_LBase && u1 < Hangul_SBase + Hangul_SCount) {
// compute Hangul syllable composition as per UAX #15
// hangul L-V pair
- const uint LIndex = u1 - Hangul_LBase;
+ const char32_t LIndex = u1 - Hangul_LBase;
if (LIndex < Hangul_LCount) {
- const uint VIndex = u2 - Hangul_VBase;
+ const char32_t VIndex = u2 - Hangul_VBase;
if (VIndex < Hangul_VCount)
return Hangul_SBase + (LIndex * Hangul_VCount + VIndex) * Hangul_TCount;
}
// hangul LV-T pair
- const uint SIndex = u1 - Hangul_SBase;
+ const char32_t SIndex = u1 - Hangul_SBase;
if (SIndex < Hangul_SCount && (SIndex % Hangul_TCount) == 0) {
- const uint TIndex = u2 - Hangul_TBase;
+ const char32_t TIndex = u2 - Hangul_TBase;
if (TIndex < Hangul_TCount && TIndex)
return u1 + TIndex;
}
@@ -1910,19 +1910,19 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype
{
QString &s = *str;
- if (from < 0 || s.length() - from < 2)
+ if (from < 0 || s.size() - from < 2)
return;
- uint stcode = 0; // starter code point
+ char32_t stcode = 0; // starter code point
qsizetype starter = -1; // starter position
qsizetype next = -1; // to prevent i == next
int lastCombining = 255; // to prevent combining > lastCombining
qsizetype pos = from;
- while (pos < s.length()) {
+ while (pos < s.size()) {
qsizetype i = pos;
char32_t uc = s.at(pos).unicode();
- if (QChar(uc).isHighSurrogate() && pos < s.length()-1) {
+ if (QChar(uc).isHighSurrogate() && pos < s.size()-1) {
ushort low = s.at(pos+1).unicode();
if (QChar(low).isLowSurrogate()) {
uc = QChar::surrogateToUcs4(uc, low);
@@ -1942,7 +1942,7 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype
int combining = p->combiningClass;
if ((i == next || combining > lastCombining) && starter >= from) {
// allowed to form ligature with S
- uint ligature = ligatureHelper(stcode, uc);
+ char32_t ligature = ligatureHelper(stcode, uc);
if (ligature) {
stcode = ligature;
QChar *d = s.data();
@@ -1969,7 +1969,7 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype
static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, qsizetype from)
{
QString &s = *str;
- const qsizetype l = s.length()-1;
+ const qsizetype l = s.size()-1;
char32_t u1, u2;
char16_t c1, c2;
@@ -2058,7 +2058,7 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo
enum { NFQC_YES = 0, NFQC_NO = 1, NFQC_MAYBE = 3 };
const ushort *string = reinterpret_cast<const ushort *>(str->constData());
- qsizetype length = str->length();
+ qsizetype length = str->size();
// this avoids one out of bounds check in the loop
while (length > from && QChar::isHighSurrogate(string[length - 1]))
@@ -2101,8 +2101,8 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo
*lastStable = pos;
}
- if (length != str->length()) // low surrogate parts at the end of text
- *lastStable = str->length() - 1;
+ if (length != str->size()) // low surrogate parts at the end of text
+ *lastStable = str->size() - 1;
return true;
}
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 65b8e03890..0525d5ac23 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -46,6 +46,8 @@ QT_WARNING_DISABLE_GCC("-Wfree-nonheap-object") // false positive tracking
#include "private/qgregoriancalendar_p.h"
#include "qcalendar.h"
+#include <q20iterator.h>
+
QT_BEGIN_NAMESPACE
QT_IMPL_METATYPE_EXTERN_TAGGED(QList<Qt::DayOfWeek>, QList_Qt__DayOfWeek)
@@ -175,7 +177,7 @@ QLocale::Script QLocalePrivate::codeToScript(QStringView code) noexcept
unsigned char c3 = code[3].toLower().toLatin1();
const unsigned char *c = script_code_list;
- for (int i = 0; i < QLocale::LastScript; ++i, c += 4) {
+ for (qsizetype i = 0; i < QLocale::LastScript; ++i, c += 4) {
if (c0 == c[0] && c1 == c[1] && c2 == c[2] && c3 == c[3])
return QLocale::Script(i);
}
@@ -461,9 +463,9 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const
return m_data->id().withLikelySubtagsRemoved().name(separator);
}
-static int findLocaleIndexById(const QLocaleId &localeId)
+static qsizetype findLocaleIndexById(const QLocaleId &localeId)
{
- quint16 idx = locale_index[localeId.language_id];
+ qsizetype idx = locale_index[localeId.language_id];
// If there are no locales for specified language (so we we've got the
// default language, which has no associated script or country), give up:
if (localeId.language_id && idx == 0)
@@ -480,14 +482,14 @@ static int findLocaleIndexById(const QLocaleId &localeId)
return -1;
}
-int QLocaleData::findLocaleIndex(QLocaleId lid)
+qsizetype QLocaleData::findLocaleIndex(QLocaleId lid)
{
QLocaleId localeId = lid;
QLocaleId likelyId = localeId.withLikelySubtagsAdded();
const ushort fallback = likelyId.language_id;
// Try a straight match with the likely data:
- int index = findLocaleIndexById(likelyId);
+ qsizetype index = findLocaleIndexById(likelyId);
if (index >= 0)
return index;
QVarLengthArray<QLocaleId, 6> tried;
@@ -530,13 +532,13 @@ int QLocaleData::findLocaleIndex(QLocaleId lid)
return locale_index[fallback];
}
-static QStringView findTag(QStringView name)
+static QStringView findTag(QStringView name) noexcept
{
- const QString separators = QStringLiteral("_-.@");
- int i = 0;
- while (i < name.size() && !separators.contains(name[i]))
- i++;
- return name.first(i);
+ const std::u16string_view v(name.utf16(), size_t(name.size()));
+ const auto i = v.find_first_of(u"_-.@");
+ if (i == std::string_view::npos)
+ return name;
+ return name.first(qsizetype(i));
}
static bool validTag(QStringView tag)
@@ -557,7 +559,7 @@ static bool isScript(QStringView tag)
static const QString allScripts =
QString::fromLatin1(reinterpret_cast<const char *>(script_code_list),
sizeof(script_code_list) - 1);
- return tag.length() == 4 && allScripts.indexOf(tag) % 4 == 0;
+ return tag.size() == 4 && allScripts.indexOf(tag) % 4 == 0;
}
bool qt_splitLocaleName(QStringView name, QStringView *lang, QStringView *script, QStringView *land)
@@ -618,9 +620,9 @@ QLocaleId QLocaleId::fromName(QStringView name)
return { langId, QLocalePrivate::codeToScript(script), QLocalePrivate::codeToTerritory(land) };
}
-QString qt_readEscapedFormatString(QStringView format, int *idx)
+QString qt_readEscapedFormatString(QStringView format, qsizetype *idx)
{
- int &i = *idx;
+ qsizetype &i = *idx;
Q_ASSERT(format.at(i) == u'\'');
++i;
@@ -796,7 +798,7 @@ static const QLocaleData *defaultData()
return default_data;
}
-static uint defaultIndex()
+static qsizetype defaultIndex()
{
const QLocaleData *const data = defaultData();
#ifndef QT_NO_SYSTEMLOCALE
@@ -807,8 +809,8 @@ static uint defaultIndex()
}
#endif
- Q_ASSERT(data >= locale_data);
- Q_ASSERT(data < locale_data + std::size(locale_data));
+ using QtPrivate::q_points_into_range;
+ Q_ASSERT(q_points_into_range(data, locale_data, std::end(locale_data)));
return data - locale_data;
}
@@ -834,7 +836,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l)
}
#endif // QT_NO_DATASTREAM
-static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1;
+static constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1; // trailing guard
Q_CONSTINIT QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0);
Q_GLOBAL_STATIC(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
@@ -844,8 +846,8 @@ static QLocalePrivate *localePrivateByName(QStringView name)
{
if (name == u"C")
return c_private();
- const int index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name));
- Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1);
+ const qsizetype index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name));
+ Q_ASSERT(index >= 0 && index < locale_data_size);
return new QLocalePrivate(locale_data + index, index,
locale_data[index].m_language_id == QLocale::C
? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions);
@@ -857,8 +859,8 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
if (language == QLocale::C)
return c_private();
- int index = QLocaleData::findLocaleIndex(QLocaleId { language, script, territory });
- Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1);
+ qsizetype index = QLocaleData::findLocaleIndex(QLocaleId { language, script, territory });
+ Q_ASSERT(index >= 0 && index < locale_data_size);
const QLocaleData *data = locale_data + index;
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions;
@@ -873,29 +875,41 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
return new QLocalePrivate(data, index, numberOptions);
}
-QString QLocaleData::decimalPoint() const
+static std::optional<QString>
+systemLocaleString(const QLocaleData *that, QSystemLocale::QueryType type)
{
#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::DecimalPoint).toString();
- if (!res.isEmpty())
- return res;
- }
+ if (that != &systemLocaleData)
+ return std::nullopt;
+
+ QVariant v = systemLocale()->query(type);
+ if (v.metaType() != QMetaType::fromType<QString>())
+ return std::nullopt;
+
+ return v.toString();
+#else
+ Q_UNUSED(that)
+ Q_UNUSED(type)
+ return std::nullopt;
#endif
- return decimalSeparator().getData(single_character_data);
+}
+
+static QString localeString(const QLocaleData *that, QSystemLocale::QueryType type,
+ QLocaleData::DataRange range)
+{
+ if (auto opt = systemLocaleString(that, type))
+ return *opt;
+ return range.getData(single_character_data);
+}
+
+QString QLocaleData::decimalPoint() const
+{
+ return localeString(this, QSystemLocale::DecimalPoint, decimalSeparator());
}
QString QLocaleData::groupSeparator() const
{
- // Empty => don't do grouping
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- QVariant res = systemLocale()->query(QSystemLocale::GroupSeparator);
- if (!res.isNull())
- return res.toString();
- }
-#endif
- return groupDelim().getData(single_character_data);
+ return localeString(this, QSystemLocale::GroupSeparator, groupDelim());
}
QString QLocaleData::percentSign() const
@@ -910,14 +924,7 @@ QString QLocaleData::listSeparator() const
QString QLocaleData::zeroDigit() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::ZeroDigit).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return zero().getData(single_character_data);
+ return localeString(this, QSystemLocale::ZeroDigit, zero());
}
char32_t QLocaleData::zeroUcs() const
@@ -938,26 +945,12 @@ char32_t QLocaleData::zeroUcs() const
QString QLocaleData::negativeSign() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::NegativeSign).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return minus().getData(single_character_data);
+ return localeString(this, QSystemLocale::NegativeSign, minus());
}
QString QLocaleData::positiveSign() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::PositiveSign).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return plus().getData(single_character_data);
+ return localeString(this, QSystemLocale::PositiveSign, plus());
}
QString QLocaleData::exponentSeparator() const
@@ -2099,7 +2092,7 @@ QString QLocale::toString(QDate date, FormatType format) const
static bool timeFormatContainsAP(QStringView format)
{
- int i = 0;
+ qsizetype i = 0;
while (i < format.size()) {
if (format.at(i).unicode() == '\'') {
qt_readEscapedFormatString(format, &i);
@@ -2620,21 +2613,17 @@ static bool qIsUpper(char c)
The \a format defaults to \c{'g'}. It can be any of the following:
\table
- \header \li Format \li Meaning
- \row \li \c 'e' \li format as [-]9.9e[+|-]999
- \row \li \c 'E' \li format as [-]9.9E[+|-]999
- \row \li \c 'f' \li format as [-]9.9
- \row \li \c 'F' \li same as \c 'f' except for INF and NAN (see below)
- \row \li \c 'g' \li use \c 'e' or \c 'f' format, whichever is more concise
- \row \li \c 'G' \li use \c 'E' or \c 'F' format, whichever is more concise
+ \header \li Format \li Meaning \li Meaning of \a precision
+ \row \li \c 'e' \li format as [-]9.9e[+|-]999 \li number of digits \e after the decimal point
+ \row \li \c 'E' \li format as [-]9.9E[+|-]999 \li "
+ \row \li \c 'f' \li format as [-]9.9 \li "
+ \row \li \c 'F' \li same as \c 'f' except for INF and NAN (see below) \li "
+ \row \li \c 'g' \li use \c 'e' or \c 'f' format, whichever is more concise \li maximum number of significant digits (trailing zeroes are omitted)
+ \row \li \c 'G' \li use \c 'E' or \c 'F' format, whichever is more concise \li "
\endtable
- For the \c 'e', \c 'E', \c 'f' and \c 'F' formats, the \a precision
- represents the number of digits \e after the decimal point. For the \c 'g'
- and \c 'G' formats, the \a precision represents the maximum number of
- significant digits (trailing zeroes are omitted). The special \a precision
- value QLocale::FloatingPointShortest selects the shortest representation
- that, when read as a number, gets back the original floating-point
+ The special \a precision value QLocale::FloatingPointShortest selects the
+ shortest representation that, when read as a number, gets back the original floating-point
value. Aside from that, any negative \a precision is ignored in favor of the
default, 6.
@@ -3325,7 +3314,7 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &
day = parts.day;
}
- int i = 0;
+ qsizetype i = 0;
while (i < format.size()) {
if (format.at(i).unicode() == '\'') {
result.append(qt_readEscapedFormatString(format, &i));
@@ -3586,7 +3575,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
Q_ASSERT(!zero.at(0).isSurrogate());
char16_t z = zero.at(0).unicode();
char16_t *const value = reinterpret_cast<char16_t *>(digits.data());
- for (int i = 0; i < digits.length(); ++i)
+ for (qsizetype i = 0; i < digits.size(); ++i)
value[i] = unicodeForDigit(value[i] - '0', z);
}
@@ -3634,7 +3623,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
// Assume digitCount < 95, so we can ignore the 3-digit
// exponent case (we'll set useDecimal false anyway).
- const int digitCount = digits.length() / zero.size();
+ const qsizetype digitCount = digits.size() / zero.size();
if (!mustMarkDecimal) {
// Decimal separator is skipped if at end; adjust if
// that happens for only one form:
@@ -3668,7 +3657,7 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
// Pad with zeros. LeftAdjusted overrides ZeroPadded.
if (flags & ZeroPadded && !(flags & LeftAdjusted)) {
- for (int i = numStr.length() / zero.length() + prefix.size(); i < width; ++i)
+ for (qsizetype i = numStr.size() / zero.size() + prefix.size(); i < width; ++i)
numStr.prepend(zero);
}
}
@@ -3691,30 +3680,30 @@ QString QLocaleData::decimalForm(QString &&digits, int decpt, int precision,
for (; decpt < 0; ++decpt)
digits.prepend(zero);
} else {
- for (int i = digits.length() / digitWidth; i < decpt; ++i)
+ for (qsizetype i = digits.size() / digitWidth; i < decpt; ++i)
digits.append(zero);
}
switch (pm) {
case PMDecimalDigits:
- for (int i = digits.length() / digitWidth - decpt; i < precision; ++i)
+ for (qsizetype i = digits.size() / digitWidth - decpt; i < precision; ++i)
digits.append(zero);
break;
case PMSignificantDigits:
- for (int i = digits.length() / digitWidth; i < precision; ++i)
+ for (qsizetype i = digits.size() / digitWidth; i < precision; ++i)
digits.append(zero);
break;
case PMChopTrailingZeros:
- Q_ASSERT(digits.length() / digitWidth <= qMax(decpt, 1) || !digits.endsWith(zero));
+ Q_ASSERT(digits.size() / digitWidth <= qMax(decpt, 1) || !digits.endsWith(zero));
break;
}
- if (mustMarkDecimal || decpt < digits.length() / digitWidth)
+ if (mustMarkDecimal || decpt < digits.size() / digitWidth)
digits.insert(decpt * digitWidth, decimalPoint());
if (groupDigits) {
const QString group = groupSeparator();
- int i = decpt - m_grouping_least;
+ qsizetype i = decpt - m_grouping_least;
if (i >= m_grouping_top) {
digits.insert(i * digitWidth, group);
while ((i -= m_grouping_higher) >= m_grouping_top)
@@ -3739,19 +3728,19 @@ QString QLocaleData::exponentForm(QString &&digits, int decpt, int precision,
switch (pm) {
case PMDecimalDigits:
- for (int i = digits.length() / digitWidth; i < precision + 1; ++i)
+ for (qsizetype i = digits.size() / digitWidth; i < precision + 1; ++i)
digits.append(zero);
break;
case PMSignificantDigits:
- for (int i = digits.length() / digitWidth; i < precision; ++i)
+ for (qsizetype i = digits.size() / digitWidth; i < precision; ++i)
digits.append(zero);
break;
case PMChopTrailingZeros:
- Q_ASSERT(digits.length() / digitWidth <= 1 || !digits.endsWith(zero));
+ Q_ASSERT(digits.size() / digitWidth <= 1 || !digits.endsWith(zero));
break;
}
- if (mustMarkDecimal || digits.length() > digitWidth)
+ if (mustMarkDecimal || digits.size() > digitWidth)
digits.insert(digitWidth, decimalPoint());
digits.append(exponentSeparator());
@@ -3800,7 +3789,7 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
{
const QString zero = base == 10 ? zeroDigit() : QStringLiteral("0");
const auto digitWidth = zero.size();
- const auto digitCount = numStr.length() / digitWidth;
+ const auto digitCount = numStr.size() / digitWidth;
const auto basePrefix = [&] () -> QStringView {
if (flags & ShowBase) {
@@ -3817,11 +3806,11 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
const QString prefix = signPrefix(negative, flags) + basePrefix;
// Count how much of width we've used up. Each digit counts as one
- int usedWidth = digitCount + prefix.size();
+ qsizetype usedWidth = digitCount + prefix.size();
if (base == 10 && flags & GroupDigits) {
const QString group = groupSeparator();
- int i = digitCount - m_grouping_least;
+ qsizetype i = digitCount - m_grouping_least;
if (i >= m_grouping_top) {
numStr.insert(i * digitWidth, group);
++usedWidth;
@@ -3837,7 +3826,7 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
if (noPrecision)
precision = 1;
- for (int i = numStr.length(); i < precision; ++i) {
+ for (qsizetype i = numStr.size(); i < precision; ++i) {
numStr.prepend(zero);
usedWidth++;
}
@@ -3845,7 +3834,7 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
// LeftAdjusted overrides ZeroPadded; and sprintf() only pads when
// precision is not specified in the format string.
if (noPrecision && flags & ZeroPadded && !(flags & LeftAdjusted)) {
- for (int i = usedWidth; i < width; ++i)
+ for (qsizetype i = usedWidth; i < width; ++i)
numStr.prepend(zero);
}
@@ -3874,11 +3863,11 @@ bool QLocaleData::numberToCLocale(QStringView s, QLocale::NumberOptions number_o
auto length = s.size();
decltype(length) idx = 0;
- int digitsInGroup = 0;
- int decpt_idx = -1;
- int last_separator_idx = -1;
- int start_of_digits_idx = -1;
- int exponent_idx = -1;
+ qsizetype digitsInGroup = 0;
+ qsizetype decpt_idx = -1;
+ qsizetype last_separator_idx = -1;
+ qsizetype start_of_digits_idx = -1;
+ qsizetype exponent_idx = -1;
while (idx < length) {
const QStringView in = QStringView(uc + idx, uc[idx].isHighSurrogate() ? 2 : 1);
@@ -3993,7 +3982,7 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray
int decDigits, QLocale::NumberOptions number_options) const
{
buff->clear();
- buff->reserve(str.length());
+ buff->reserve(str.size());
enum { Whole, Fractional, Exponent } state = Whole;
const bool scientific = numMode == DoubleScientificMode;
@@ -4089,7 +4078,7 @@ double QLocaleData::stringToDouble(QStringView str, bool *ok,
}
int processed = 0;
bool nonNullOk = false;
- double d = qt_asciiToDouble(buff.constData(), buff.length() - 1, nonNullOk, processed);
+ double d = qt_asciiToDouble(buff.constData(), buff.size() - 1, nonNullOk, processed);
if (ok != nullptr)
*ok = nonNullOk;
return d;
@@ -4123,17 +4112,8 @@ qulonglong QLocaleData::stringToUnsLongLong(QStringView str, int base, bool *ok,
qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *ok)
{
- if (num.isEmpty() || num.at(0) == '\0') {
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
-
- bool _ok;
- const char *endptr;
- const qlonglong l = qstrntoll(num.data(), num.size(), &endptr, base, &_ok);
-
- if (!_ok || endptr == num.data()) {
+ auto [l, endptr] = qstrntoll(num.data(), num.size(), base);
+ if (!endptr) {
if (ok != nullptr)
*ok = false;
return 0;
@@ -4159,17 +4139,8 @@ qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *o
qulonglong QLocaleData::bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok)
{
- if (num.isEmpty() || num.at(0) == '\0') {
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
-
- bool _ok;
- const char *endptr;
- const qulonglong l = qstrntoull(num.data(), num.size(), &endptr, base, &_ok);
-
- if (!_ok || endptr == num.data()) {
+ auto [l, endptr] = qstrntoull(num.data(), num.size(), base);
+ if (!endptr) {
if (ok != nullptr)
*ok = false;
return 0;
@@ -4225,7 +4196,7 @@ QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format) const
case CurrencyIsoCode: {
const char *code = d->m_data->m_currency_iso_code;
if (auto len = qstrnlen(code, 3))
- return QString::fromLatin1(code, int(len));
+ return QString::fromLatin1(code, qsizetype(len));
break;
}
}
@@ -4417,17 +4388,35 @@ QStringList QLocale::uiLanguages() const
locales.append(QLocale(entry));
if (locales.isEmpty())
locales.append(systemLocale()->fallbackLocale());
+ // If the system locale (isn't C and) didn't include itself in the list,
+ // or as fallback, presume to know better than it and put its name
+ // first. (Known issue, QTBUG-104930, on some macOS versions when in
+ // locale en_DE.) Our translation system might have a translation for a
+ // locale the platform doesn't believe in.
+ const QString name = bcp47Name();
+ if (!name.isEmpty() && language() != C && !uiLanguages.contains(name)) {
+ // That uses contains(name) as a cheap pre-test, but there may be an
+ // entry that matches this on purging likely subtags.
+ const QLocaleId mine = d->m_data->id().withLikelySubtagsRemoved();
+ const auto isMine = [mine](const QString &entry) {
+ return QLocaleId::fromName(entry).withLikelySubtagsRemoved() == mine;
+ };
+ if (std::none_of(uiLanguages.constBegin(), uiLanguages.constEnd(), isMine)) {
+ locales.prepend(*this);
+ uiLanguages.prepend(name);
+ }
+ }
} else
#endif
{
locales.append(*this);
}
- for (int i = locales.size(); i-- > 0; ) {
+ for (qsizetype i = locales.size(); i-- > 0; ) {
const QLocale &locale = locales.at(i);
const auto data = locale.d->m_data;
QLocaleId id = data->id();
- int j;
+ qsizetype j;
QByteArray prior;
if (isSystem && i < uiLanguages.size()) {
// Adding likely-adjusted forms to system locale's list.
diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm
index 9a9cc4d158..f3ca942845 100644
--- a/src/corelib/text/qlocale_mac.mm
+++ b/src/corelib/text/qlocale_mac.mm
@@ -254,7 +254,7 @@ static QVariant macTimeToString(QTime time, bool short_format)
static QVariant macToQtFormat(QStringView sys_fmt)
{
QString result;
- int i = 0;
+ qsizetype i = 0;
while (i < sys_fmt.size()) {
if (sys_fmt.at(i).unicode() == '\'') {
@@ -589,9 +589,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
case UILanguages: {
QStringList result;
QCFType<CFArrayRef> languages = CFLocaleCopyPreferredLanguages();
- const int cnt = CFArrayGetCount(languages);
+ const CFIndex cnt = CFArrayGetCount(languages);
result.reserve(cnt);
- for (int i = 0; i < cnt; ++i) {
+ for (CFIndex i = 0; i < cnt; ++i) {
const QString lang = QString::fromCFString(
static_cast<CFStringRef>(CFArrayGetValueAtIndex(languages, i)));
result.append(lang);
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h
index 061e566d68..121e6123a2 100644
--- a/src/corelib/text/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -31,7 +31,6 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_SYSTEMLOCALE
struct QLocaleData;
// Subclassed by Android platform plugin:
class Q_CORE_EXPORT QSystemLocale
@@ -101,14 +100,13 @@ public:
virtual QVariant query(QueryType type, QVariant in = QVariant()) const;
virtual QLocale fallbackLocale() const;
- inline uint fallbackLocaleIndex() const;
+ inline qsizetype fallbackLocaleIndex() const;
private:
QSystemLocale(bool);
friend class QSystemLocaleSingleton;
};
Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_RELOCATABLE_TYPE);
-#endif
#if QT_CONFIG(icu)
namespace QIcu {
@@ -161,7 +159,7 @@ struct QLocaleData
public:
// Having an index for each locale enables us to have diverse sources of
// data, e.g. calendar locales, as well as the main CLDR-derived data.
- [[nodiscard]] static int findLocaleIndex(QLocaleId localeId);
+ [[nodiscard]] static qsizetype findLocaleIndex(QLocaleId localeId);
[[nodiscard]] static const QLocaleData *c();
enum DoubleForm {
@@ -292,11 +290,11 @@ public:
{
return { reinterpret_cast<const QChar *>(table + offset), size };
}
- [[nodiscard]] QString getListEntry(const char16_t *table, int index) const
+ [[nodiscard]] QString getListEntry(const char16_t *table, qsizetype index) const
{
return listEntry(table, index).getData(table);
}
- [[nodiscard]] QStringView viewListEntry(const char16_t *table, int index) const
+ [[nodiscard]] QStringView viewListEntry(const char16_t *table, qsizetype index) const
{
return listEntry(table, index).viewData(table);
}
@@ -309,7 +307,7 @@ public:
return 0;
}
private:
- [[nodiscard]] DataRange listEntry(const char16_t *table, int index) const
+ [[nodiscard]] DataRange listEntry(const char16_t *table, qsizetype index) const
{
const char16_t separator = ';';
quint16 i = 0;
@@ -372,7 +370,7 @@ public:
class QLocalePrivate
{
public:
- constexpr QLocalePrivate(const QLocaleData *data, const uint index,
+ constexpr QLocalePrivate(const QLocaleData *data, qsizetype index,
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions,
int refs = 0)
: m_data(data), ref Q_BASIC_ATOMIC_INITIALIZER(refs),
@@ -410,14 +408,14 @@ public:
// System locale has an m_data all its own; all others have m_data = locale_data + m_index
const QLocaleData *const m_data;
QBasicAtomicInt ref;
- const uint m_index;
+ const qsizetype m_index;
QLocale::NumberOptions m_numberOptions;
static QBasicAtomicInt s_generation;
};
#ifndef QT_NO_SYSTEMLOCALE
-uint QSystemLocale::fallbackLocaleIndex() const { return fallbackLocale().d->m_index; }
+qsizetype QSystemLocale::fallbackLocaleIndex() const { return fallbackLocale().d->m_index; }
#endif
template <>
@@ -476,7 +474,7 @@ inline char QLocaleData::numericToCLocale(QStringView in) const
// Also used to merely skip over an escape in a format string, advancint idx to
// point after it (so not [[nodiscard]]):
-QString qt_readEscapedFormatString(QStringView format, int *idx);
+QString qt_readEscapedFormatString(QStringView format, qsizetype *idx);
[[nodiscard]] bool qt_splitLocaleName(QStringView name, QStringView *lang = nullptr,
QStringView *script = nullptr, QStringView *cntry = nullptr);
[[nodiscard]] qsizetype qt_repeatCount(QStringView s);
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index e34cc1c947..c211e57812 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -191,11 +191,10 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
// which case the missing digits are zeroes. In the 'e' case decptInTarget is always 1,
// as variants of snprintf always generate numbers with one digit before the '.' then.
// This is why the final decimal point is offset by 1, relative to the number after 'e'.
- bool ok;
- const char *endptr;
- decpt = qstrntoll(target.data() + eSign + 1, length - eSign - 1, &endptr, 10, &ok) + 1;
- Q_ASSERT(ok);
- Q_ASSERT(endptr - target.data() <= length);
+ auto r = qstrntoll(target.data() + eSign + 1, length - eSign - 1, 10);
+ decpt = r.result + 1;
+ Q_ASSERT(r.ok());
+ Q_ASSERT(r.endptr - target.data() <= length);
} else {
// No 'e' found, so it's the 'f' form. Variants of snprintf generate numbers with
// potentially multiple digits before the '.', but without decimal exponent then. So we
@@ -423,36 +422,25 @@ static bool isDigitForBase(char d, int base)
return false;
}
-unsigned long long
-qstrntoull(const char *begin, qsizetype size, const char **endptr, int base, bool *ok)
+QSimpleParsedNumber<qulonglong> qstrntoull(const char *begin, qsizetype size, int base)
{
const char *p = begin, *const stop = begin + size;
while (p < stop && ascii_isspace(*p))
++p;
unsigned long long result = 0;
- if (p >= stop || *p == '-') {
- *ok = false;
- if (endptr)
- *endptr = begin;
- return result;
- }
+ if (p >= stop || *p == '-')
+ return { };
const auto prefix = scanPrefix(*p == '+' ? p + 1 : p, stop, base);
- if (!prefix.base || prefix.next >= stop) {
- if (endptr)
- *endptr = begin;
- *ok = false;
- return 0;
- }
+ if (!prefix.base || prefix.next >= stop)
+ return { };
const auto res = std::from_chars(prefix.next, stop, result, prefix.base);
- *ok = res.ec == std::errc{};
- if (endptr)
- *endptr = res.ptr == prefix.next ? begin : res.ptr;
- return result;
+ if (res.ec != std::errc{})
+ return { };
+ return { result, res.ptr == prefix.next ? begin : res.ptr };
}
-long long
-qstrntoll(const char *begin, qsizetype size, const char **endptr, int base, bool *ok)
+QSimpleParsedNumber<qlonglong> qstrntoll(const char *begin, qsizetype size, int base)
{
const char *p = begin, *const stop = begin + size;
while (p < stop && ascii_isspace(*p))
@@ -467,30 +455,22 @@ qstrntoll(const char *begin, qsizetype size, const char **endptr, int base, bool
const auto prefix = scanPrefix(p, stop, base);
// Must check for digit, as from_chars() will accept a sign, which would be
// a second sign, that we should reject.
- if (!prefix.base || prefix.next >= stop || !isDigitForBase(*prefix.next, prefix.base)) {
- if (endptr)
- *endptr = begin;
- *ok = false;
- return 0;
- }
+ if (!prefix.base || prefix.next >= stop || !isDigitForBase(*prefix.next, prefix.base))
+ return { };
long long result = 0;
auto res = std::from_chars(prefix.next, stop, result, prefix.base);
- *ok = res.ec == std::errc{};
if (negate && res.ec == std::errc::result_out_of_range) {
// Maybe LLONG_MIN:
unsigned long long check = 0;
res = std::from_chars(prefix.next, stop, check, prefix.base);
- if (res.ec == std::errc{} && check + std::numeric_limits<long long>::min() == 0) {
- *ok = true;
- if (endptr)
- *endptr = res.ptr;
- return std::numeric_limits<long long>::min();
- }
+ if (res.ec == std::errc{} && check + std::numeric_limits<long long>::min() == 0)
+ return { std::numeric_limits<long long>::min(), res.ptr };
+ return { };
}
- if (endptr)
- *endptr = res.ptr == prefix.next ? begin : res.ptr;
- return negate && *ok ? -result : result;
+ if (res.ec != std::errc{})
+ return { };
+ return { negate ? -result : result, res.ptr };
}
template <typename Char>
@@ -687,7 +667,7 @@ static T dtoString(double d, QLocaleData::DoubleForm form, int precision, bool u
bool negative = false;
int length = 0;
int decpt = 0;
- qt_doubleToAscii(d, form, precision, buffer.data(), buffer.length(), negative, length, decpt);
+ qt_doubleToAscii(d, form, precision, buffer.data(), buffer.size(), negative, length, decpt);
QLatin1StringView view(buffer.data(), length);
const bool succinct = form == QLocaleData::DFSignificantDigits;
qsizetype total = (negative ? 1 : 0) + length;
diff --git a/src/corelib/text/qlocale_tools_p.h b/src/corelib/text/qlocale_tools_p.h
index 2f676eced5..b5eb4d344b 100644
--- a/src/corelib/text/qlocale_tools_p.h
+++ b/src/corelib/text/qlocale_tools_p.h
@@ -26,6 +26,13 @@ enum StrayCharacterMode {
WhitespacesAllowed
};
+template <typename T> struct QSimpleParsedNumber
+{
+ T result;
+ const char *endptr;
+ bool ok() { return endptr; }
+};
+
// API note: this function can't process a number with more than 2.1 billion digits
[[nodiscard]] double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &processed,
StrayCharacterMode strayCharMode = TrailingJunkProhibited);
@@ -81,10 +88,8 @@ template <typename UcsInt>
return qstrntod(s00, len, se, ok);
}
-[[nodiscard]] qlonglong qstrntoll(const char *nptr, qsizetype size, const char **endptr,
- int base, bool *ok);
-[[nodiscard]] qulonglong qstrntoull(const char *nptr, qsizetype size, const char **endptr,
- int base, bool *ok);
+[[nodiscard]] QSimpleParsedNumber<qlonglong> qstrntoll(const char *nptr, qsizetype size, int base);
+[[nodiscard]] QSimpleParsedNumber<qulonglong> qstrntoull(const char *nptr, qsizetype size, int base);
QT_END_NAMESPACE
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index f61c724aee..0e0716cc65 100644
--- a/src/corelib/text/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
@@ -18,14 +18,8 @@
#endif
#if QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
-# include <winrt/base.h>
-// Workaround for Windows SDK bug.
-// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
-namespace winrt::impl
-{
- template <typename Async>
- auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
-}
+# include <QtCore/private/qt_winrtbase_p.h>
+
# include <winrt/Windows.Foundation.h>
# include <winrt/Windows.Foundation.Collections.h>
# include <winrt/Windows.System.UserProfile.h>
@@ -224,7 +218,7 @@ QString QSystemLocalePrivate::substituteDigits(QString &&string)
break;
Q_ASSERT(z > '9');
ushort *const qch = reinterpret_cast<ushort *>(string.data());
- for (int i = 0, stop = string.size(); i < stop; ++i) {
+ for (qsizetype i = 0, stop = string.size(); i < stop; ++i) {
ushort &ch = qch[i];
if (ch >= '0' && ch <= '9')
ch = unicodeForDigit(ch - '0', z);
@@ -434,7 +428,7 @@ QString QSystemLocalePrivate::yearFix(int year, int fakeYear, QString &&formatte
if (formatted.contains(yearUsed))
return std::move(formatted).replace(yearUsed, sign + trueYear);
- const int twoDigits = 2 * zero.size();
+ const qsizetype twoDigits = 2 * zero.size();
tail = QStringView{yearUsed}.last(twoDigits);
if (formatted.contains(tail)) {
if (matchTwo)
@@ -485,11 +479,13 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type)
DWORD flags = 0;
// keep the same conditional as timeFormat() above
- if (type == QLocale::ShortFormat)
- flags = TIME_NOSECONDS;
+ const QString format = type == QLocale::ShortFormat
+ ? getLocaleInfo(LOCALE_SSHORTTIME).toString()
+ : QString();
+ auto formatStr = reinterpret_cast<const wchar_t *>(format.isEmpty() ? nullptr : format.utf16());
wchar_t buf[255];
- if (getTimeFormat(flags, &st, NULL, buf, 255)) {
+ if (getTimeFormat(flags, &st, formatStr, buf, int(std::size(buf)))) {
QString text = QString::fromWCharArray(buf);
if (substitution() == SAlways)
text = substituteDigits(std::move(text));
@@ -662,9 +658,13 @@ QVariant QSystemLocalePrivate::uiLanguages()
#if QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
using namespace winrt;
using namespace Windows::System::UserProfile;
- auto languages = GlobalizationPreferences::Languages();
- for (const auto &lang : languages)
- result << QString::fromStdString(winrt::to_string(lang));
+ QT_TRY {
+ auto languages = GlobalizationPreferences::Languages();
+ for (const auto &lang : languages)
+ result << QString::fromStdString(winrt::to_string(lang));
+ } QT_CATCH(...) {
+ // pass, just fall back to WIN32 API implementation
+ }
if (!result.isEmpty())
return result; // else just fall back to WIN32 API implementation
#endif // QT_CONFIG(cpp_winrt) && !defined(Q_CC_CLANG)
@@ -716,7 +716,7 @@ void QSystemLocalePrivate::update()
QString QSystemLocalePrivate::winToQtFormat(QStringView sys_fmt)
{
QString result;
- int i = 0;
+ qsizetype i = 0;
while (i < sys_fmt.size()) {
if (sys_fmt.at(i).unicode() == u'\'') {
@@ -1034,6 +1034,8 @@ static const char *winLangCodeToIsoName(int code)
LCID qt_inIsoNametoLCID(const char *name)
{
+ if (!name)
+ return LOCALE_USER_DEFAULT;
// handle norwegian manually, the list above will fail
if (!strncmp(name, "nb", 2))
return 0x0414;
@@ -1070,11 +1072,9 @@ static QString winIso639LangName(LCID id)
lang_code = QString::fromWCharArray(out);
if (!lang_code.isEmpty()) {
- const char *endptr;
- bool ok;
const QByteArray latin1 = std::move(lang_code).toLatin1();
- const auto i = qstrntoull(latin1.data(), latin1.size(), &endptr, 16, &ok);
- if (ok && *endptr == '\0') {
+ const auto [i, endptr] = qstrntoull(latin1.data(), latin1.size(), 16);
+ if (endptr && *endptr == '\0') {
switch (i) {
case 0x814:
result = u"nn"_s; // Nynorsk
@@ -1114,8 +1114,8 @@ static QByteArray getWinLocaleName(LCID id)
result = langEnvVar;
if (result == "C"
|| (!result.isEmpty() && qt_splitLocaleName(QString::fromLocal8Bit(result)))) {
- bool ok = false; // See if we have a Windows locale code instead of a locale name:
- long id = qstrntoll(result.data(), result.size(), 0, 0, &ok);
+ // See if we have a Windows locale code instead of a locale name:
+ auto [id, ok] = qstrntoll(result.data(), result.size(), 0);
if (!ok || id == 0 || id < INT_MIN || id > INT_MAX) // Assume real locale name
return result;
return winLangCodeToIsoName(int(id));
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index a9b7f99975..a523a64788 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -894,7 +894,7 @@ void QRegularExpressionPrivate::compilePattern()
PCRE2_SIZE patternErrorOffset;
compiledPattern = pcre2_compile_16(reinterpret_cast<PCRE2_SPTR16>(pattern.constData()),
- pattern.length(),
+ pattern.size(),
options,
&errorCode,
&patternErrorOffset,
@@ -1547,10 +1547,10 @@ QString QRegularExpression::errorString() const
QString errorString;
int errorStringLength;
do {
- errorString.resize(errorString.length() + 64);
+ errorString.resize(errorString.size() + 64);
errorStringLength = pcre2_get_error_message_16(d->errorCode,
reinterpret_cast<ushort *>(errorString.data()),
- errorString.length());
+ errorString.size());
} while (errorStringLength < 0);
errorString.resize(errorStringLength);
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 65a0bed949..59ef2b2f59 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -493,8 +493,8 @@ const char16_t *QtPrivate::qustrchr(QStringView str, char16_t c) noexcept
}
return UnrollTailLoop<3>::exec(e - n, e,
- [=](int i) { return n[i] == c; },
- [=](int i) { return n + i; });
+ [=](qsizetype i) { return n[i] == c; },
+ [=](qsizetype i) { return n + i; });
# endif
#elif defined(__ARM_NEON__)
const uint16x8_t vmask = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 };
@@ -812,7 +812,7 @@ Q_CORE_EXPORT void qt_from_latin1(char16_t *dst, const char *str, size_t size) n
dst += offset;
str += offset;
# if !defined(__OPTIMIZE_SIZE__)
- return UnrollTailLoop<7>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; });
+ return UnrollTailLoop<7>::exec(qsizetype(size), [=](qsizetype i) { dst[i] = (uchar)str[i]; });
# endif
#endif
#if defined(__mips_dsp)
@@ -939,7 +939,7 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len
src += offset;
# if !defined(__OPTIMIZE_SIZE__)
- return UnrollTailLoop<3>::exec(length, [=](int i) {
+ return UnrollTailLoop<3>::exec(length, [=](qsizetype i) {
if (Checked)
dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i];
else
@@ -2652,11 +2652,11 @@ void QString::resize(qsizetype size)
\snippet qstring/main.cpp 46
*/
-void QString::resize(qsizetype size, QChar fillChar)
+void QString::resize(qsizetype newSize, QChar fillChar)
{
- const qsizetype oldSize = length();
- resize(size);
- const qsizetype difference = length() - oldSize;
+ const qsizetype oldSize = size();
+ resize(newSize);
+ const qsizetype difference = size() - oldSize;
if (difference > 0)
std::fill_n(d.data() + oldSize, difference, fillChar.unicode());
}
@@ -3040,6 +3040,14 @@ QString &QString::append(const QString &str)
}
/*!
+ \fn QString &QString::append(QStringView v)
+ \overload append()
+ \since 6.0
+
+ Appends the given string view \a v to this string and returns the result.
+*/
+
+/*!
\overload append()
\since 5.0
@@ -3380,7 +3388,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs)
*/
QString &QString::replace(qsizetype pos, qsizetype len, const QString &after)
{
- return replace(pos, len, after.constData(), after.length());
+ return replace(pos, len, after.constData(), after.size());
}
/*!
@@ -4102,7 +4110,7 @@ QString &QString::replace(QChar c, QLatin1StringView after, Qt::CaseSensitivity
*/
qsizetype QString::indexOf(const QString &str, qsizetype from, Qt::CaseSensitivity cs) const
{
- return QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs);
+ return QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs);
}
/*!
@@ -4156,7 +4164,7 @@ qsizetype QString::indexOf(QLatin1StringView str, qsizetype from, Qt::CaseSensit
*/
qsizetype QString::indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const
{
- return qFindChar(QStringView(unicode(), length()), ch, from, cs);
+ return qFindChar(QStringView(unicode(), size()), ch, from, cs);
}
/*!
@@ -4356,7 +4364,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
// 1. build the backreferences list, holding where the backreferences
// are in the replacement string
QList<QStringCapture> backReferences;
- const qsizetype al = after.length();
+ const qsizetype al = after.size();
const QChar *ac = after.unicode();
for (qsizetype i = 0; i < al - 1; i++) {
@@ -4401,7 +4409,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
lastEnd = 0;
// add the after string, with replacements for the backreferences
- for (const QStringCapture &backReference : qAsConst(backReferences)) {
+ for (const QStringCapture &backReference : std::as_const(backReferences)) {
// part of "after" before the backreference
len = backReference.pos - lastEnd;
if (len > 0) {
@@ -4420,7 +4428,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
}
// add the last part of the after string
- len = afterView.length() - lastEnd;
+ len = afterView.size() - lastEnd;
if (len > 0) {
chunks << afterView.mid(lastEnd, len);
newLength += len;
@@ -4430,17 +4438,17 @@ QString &QString::replace(const QRegularExpression &re, const QString &after)
}
// 3. trailing string after the last match
- if (copyView.length() > lastEnd) {
+ if (copyView.size() > lastEnd) {
chunks << copyView.mid(lastEnd);
- newLength += copyView.length() - lastEnd;
+ newLength += copyView.size() - lastEnd;
}
// 4. assemble the chunks together
resize(newLength);
qsizetype i = 0;
QChar *uc = data();
- for (const QStringView &chunk : qAsConst(chunks)) {
- qsizetype len = chunk.length();
+ for (const QStringView &chunk : std::as_const(chunks)) {
+ qsizetype len = chunk.size();
memcpy(uc + i, chunk.constData(), len * sizeof(QChar));
i += len;
}
@@ -4803,7 +4811,7 @@ static QString extractSections(const QList<qt_section_chunk> &sections, qsizetyp
qsizetype skip = 0;
for (qsizetype k = 0; k < sectionsSize; ++k) {
const qt_section_chunk &section = sections.at(k);
- if (section.length == section.string.length())
+ if (section.length == section.string.size())
skip++;
}
if (start < 0)
@@ -4819,7 +4827,7 @@ static QString extractSections(const QList<qt_section_chunk> &sections, qsizetyp
qsizetype first_i = start, last_i = end;
for (qsizetype i = 0; x <= end && i < sectionsSize; ++i) {
const qt_section_chunk &section = sections.at(i);
- const bool empty = (section.length == section.string.length());
+ const bool empty = (section.length == section.string.size());
if (x >= start) {
if (x == start)
first_i = i;
@@ -4878,7 +4886,7 @@ QString QString::section(const QRegularExpression &re, qsizetype start, qsizetyp
sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
QList<qt_section_chunk> sections;
- qsizetype n = length(), m = 0, last_m = 0, last_len = 0;
+ qsizetype n = size(), m = 0, last_m = 0, last_len = 0;
QRegularExpressionMatchIterator iterator = sep.globalMatch(*this);
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
@@ -5236,7 +5244,7 @@ static QByteArray qt_convert_to_latin1(QStringView string)
if (Q_UNLIKELY(string.isNull()))
return QByteArray();
- QByteArray ba(string.length(), Qt::Uninitialized);
+ QByteArray ba(string.size(), Qt::Uninitialized);
// since we own the only copy, we're going to const_cast the constData;
// that avoids an unnecessary call to detach() and expansion code that will never get used
@@ -5405,7 +5413,7 @@ QList<uint> QString::toUcs4() const
static QList<uint> qt_convert_to_ucs4(QStringView string)
{
- QList<uint> v(string.length());
+ QList<uint> v(string.size());
uint *a = const_cast<uint*>(v.constData());
QStringIterator it(string);
while (it.hasNext())
@@ -5610,7 +5618,7 @@ QString QString::fromUtf8(QByteArrayView ba)
host byte order is assumed.
This function is slow compared to the other Unicode conversions.
- Use QString(const QChar *, int) or QString(const QChar *) if possible.
+ Use QString(const QChar *, qsizetype) or QString(const QChar *) if possible.
QString makes a deep copy of the Unicode data.
@@ -6361,7 +6369,7 @@ int QLatin1StringView::compare_helper(const QChar *data1, qsizetype length1, QLa
*/
int QString::localeAwareCompare(const QString &other) const
{
- return localeAwareCompare_helper(constData(), length(), other.constData(), other.length());
+ return localeAwareCompare_helper(constData(), size(), other.constData(), other.size());
}
/*!
@@ -6477,7 +6485,7 @@ const ushort *QString::utf16() const
QString QString::leftJustified(qsizetype width, QChar fill, bool truncate) const
{
QString result;
- qsizetype len = length();
+ qsizetype len = size();
qsizetype padlen = width - len;
if (padlen > 0) {
result.resize(len+padlen);
@@ -6516,7 +6524,7 @@ QString QString::leftJustified(qsizetype width, QChar fill, bool truncate) const
QString QString::rightJustified(qsizetype width, QChar fill, bool truncate) const
{
QString result;
- qsizetype len = length();
+ qsizetype len = size();
qsizetype padlen = width - len;
if (padlen > 0) {
result.resize(len+padlen);
@@ -6759,14 +6767,14 @@ static int parse_field_width(const char *&c, qsizetype size)
// can't be negative - started with a digit
// contains at least one digit
- const char *endp;
- bool ok;
- const qulonglong result = qstrntoull(c, size, &endp, 10, &ok);
+ auto [result, endp] = qstrntoull(c, size, 10);
c = endp;
+ if (!endp)
+ return false;
// preserve Qt 5.5 behavior of consuming all digits, no matter how many
while (c < stop && qIsDigit(*c))
++c;
- return ok && result < qulonglong(std::numeric_limits<int>::max()) ? int(result) : 0;
+ return result < qulonglong(std::numeric_limits<int>::max()) ? int(result) : 0;
}
enum LengthMod { lm_none, lm_hh, lm_h, lm_l, lm_ll, lm_L, lm_j, lm_z, lm_t };
@@ -6872,6 +6880,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
int precision = -1; // -1 means unspecified
if (*c == '.') {
++c;
+ precision = 0;
if (qIsDigit(*c)) {
precision = parse_field_width(c, formatEnd - c);
} else if (*c == '*') { // can't parse this in another function, not portably, at least
@@ -7017,27 +7026,27 @@ QString QString::vasprintf(const char *cformat, va_list ap)
switch (length_mod) {
case lm_hh: {
signed char *n = va_arg(ap, signed char*);
- *n = result.length();
+ *n = result.size();
break;
}
case lm_h: {
short int *n = va_arg(ap, short int*);
- *n = result.length();
+ *n = result.size();
break;
}
case lm_l: {
long int *n = va_arg(ap, long int*);
- *n = result.length();
+ *n = result.size();
break;
}
case lm_ll: {
qint64 *n = va_arg(ap, qint64*);
- *n = result.length();
+ *n = result.size();
break;
}
default: {
int *n = va_arg(ap, int*);
- *n = result.length();
+ *n = result.size();
break;
}
}
@@ -7100,7 +7109,9 @@ qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
}
#endif
- return QLocaleData::c()->stringToLongLong(string, base, ok, QLocale::RejectGroupSeparator);
+ QVarLengthArray<uchar> latin1(string.size());
+ qt_to_latin1(latin1.data(), string.utf16(), string.size());
+ return QLocaleData::bytearrayToLongLong(latin1, base, ok);
}
@@ -7145,7 +7156,9 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
}
#endif
- return QLocaleData::c()->stringToUnsLongLong(string, base, ok, QLocale::RejectGroupSeparator);
+ QVarLengthArray<uchar> latin1(string.size());
+ qt_to_latin1(latin1.data(), string.utf16(), string.size());
+ return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok);
}
/*!
@@ -7356,6 +7369,11 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
double QString::toDouble(bool *ok) const
{
+ return QStringView(*this).toDouble(ok);
+}
+
+double QStringView::toDouble(bool *ok) const
+{
return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator);
}
@@ -7394,6 +7412,11 @@ float QString::toFloat(bool *ok) const
return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
}
+float QStringView::toFloat(bool *ok) const
+{
+ return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
+}
+
/*! \fn QString &QString::setNum(int n, int base)
Sets the string to the printed value of \a n in the specified \a
@@ -7671,14 +7694,15 @@ QStringList QString::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensit
\fn QList<QStringView> QStringView::split(QStringView sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const
- Splits the string into substring views wherever \a sep occurs, and
+ Splits the view into substring views wherever \a sep occurs, and
returns the list of those string views.
See QString::split() for how \a sep, \a behavior and \a cs interact to form
the result.
- \note All views are valid as long as this string is. Destroying this
- string will cause all views to be dangling pointers.
+ \note All the returned views are valid as long as the data referenced by
+ this string view is valid. Destroying the data will cause all views to
+ become dangling.
\since 6.0
*/
@@ -7839,7 +7863,7 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::
// check if it's fully ASCII first, because then we have no work
auto start = reinterpret_cast<const char16_t *>(data->constData());
const char16_t *p = start + from;
- if (isAscii_helper(p, p + data->length() - from))
+ if (isAscii_helper(p, p + data->size() - from))
return;
if (p > start + from)
from = p - start - 1; // need one before the non-ASCII to perform NFC
@@ -7859,7 +7883,7 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::
char16_t ucs4Low = QChar::lowSurrogate(n.ucs4);
char16_t oldHigh = QChar::highSurrogate(n.old_mapping);
char16_t oldLow = QChar::lowSurrogate(n.old_mapping);
- while (pos < s.length() - 1) {
+ while (pos < s.size() - 1) {
if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
if (!d)
d = data->data();
@@ -7869,7 +7893,7 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::
++pos;
}
} else {
- while (pos < s.length()) {
+ while (pos < s.size()) {
if (s.at(pos).unicode() == n.ucs4) {
if (!d)
d = data->data();
@@ -7938,9 +7962,9 @@ static void checkArgEscape(QStringView s)
struct ArgEscapeData
{
int min_escape; // lowest escape sequence number
- int occurrences; // number of occurrences of the lowest escape sequence number
- int locale_occurrences; // number of occurrences of the lowest escape sequence number that
- // contain 'L'
+ qsizetype occurrences; // number of occurrences of the lowest escape sequence number
+ qsizetype locale_occurrences; // number of occurrences of the lowest escape sequence number that
+ // contain 'L'
qsizetype escape_len; // total length of escape sequences which will be replaced
};
@@ -8026,14 +8050,14 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, qsizetyp
// Negative field-width for right-padding, positive for left-padding:
const qsizetype abs_field_width = qAbs(field_width);
const qsizetype result_len =
- s.length() - d.escape_len
- + (d.occurrences - d.locale_occurrences) * qMax(abs_field_width, arg.length())
- + d.locale_occurrences * qMax(abs_field_width, larg.length());
+ s.size() - d.escape_len
+ + (d.occurrences - d.locale_occurrences) * qMax(abs_field_width, arg.size())
+ + d.locale_occurrences * qMax(abs_field_width, larg.size());
QString result(result_len, Qt::Uninitialized);
QChar *rc = const_cast<QChar *>(result.unicode());
QChar *const result_end = rc + result_len;
- int repl_cnt = 0;
+ qsizetype repl_cnt = 0;
const QChar *c = s.begin();
const QChar *const uc_end = s.end();
@@ -8071,7 +8095,7 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, qsizetyp
rc += escape_start - text_start;
const QStringView use = localize ? larg : arg;
- const qsizetype pad_chars = abs_field_width - use.length();
+ const qsizetype pad_chars = abs_field_width - use.size();
// (If negative, relevant loops are no-ops: no need to check.)
if (field_width > 0) { // left padded
@@ -8079,8 +8103,8 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, qsizetyp
*rc++ = fillChar;
}
- memcpy(rc, use.data(), use.length() * sizeof(QChar));
- rc += use.length();
+ memcpy(rc, use.data(), use.size() * sizeof(QChar));
+ rc += use.size();
if (field_width < 0) { // right padded
for (qsizetype i = 0; i < pad_chars; ++i)
@@ -8314,7 +8338,7 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) cons
if (d.occurrences > d.locale_occurrences) {
arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= arg.length());
+ || fieldWidth <= arg.size());
}
QString localeArg;
@@ -8324,7 +8348,7 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) cons
flags |= QLocaleData::GroupDigits;
localeArg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= localeArg.length());
+ || fieldWidth <= localeArg.size());
}
return replaceArgEscapes(*this, d, fieldWidth, arg, localeArg, fillChar);
@@ -8362,7 +8386,7 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con
if (d.occurrences > d.locale_occurrences) {
arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= arg.length());
+ || fieldWidth <= arg.size());
}
QString localeArg;
@@ -8372,7 +8396,7 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con
flags |= QLocaleData::GroupDigits;
localeArg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= localeArg.length());
+ || fieldWidth <= localeArg.size());
}
return replaceArgEscapes(*this, d, fieldWidth, arg, localeArg, fillChar);
@@ -8484,7 +8508,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar
arg = QLocaleData::c()->doubleToString(a, precision, form, fieldWidth,
flags | QLocaleData::ZeroPadExponent);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= arg.length());
+ || fieldWidth <= arg.size());
}
QString localeArg;
@@ -8500,7 +8524,7 @@ QString QString::arg(double a, int fieldWidth, char format, int precision, QChar
flags |= QLocaleData::AddTrailingZeroes;
localeArg = locale.d->m_data->doubleToString(a, precision, form, fieldWidth, flags);
Q_ASSERT(fillChar != u'0' || !qIsFinite(a)
- || fieldWidth <= localeArg.length());
+ || fieldWidth <= localeArg.size());
}
return replaceArgEscapes(*this, d, fieldWidth, arg, localeArg, fillChar);
@@ -8995,8 +9019,8 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
\c{const char *} instead of QString. This includes the copy
constructor, the assignment operator, the comparison operators,
and various other functions such as \l{QString::insert()}{insert()},
- \l{QString::replace()}{replace()}, and \l{QString::indexOf()}{indexOf()}.
- These functions are usually optimized to avoid constructing a
+ \l{QString::append()}{append()}, and \l{QString::prepend()}{prepend()}.
+ Some of these functions are optimized to avoid constructing a
QString object for the \c{const char *} data. For example,
assuming \c str is a QString,
@@ -9009,6 +9033,12 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
because it doesn't construct four temporary QString objects and
make a deep copy of the character data.
+ However, that is not true for all QString member functions that take
+ \c{const char *} and therefore applications should assume a temporary will
+ be created, such as in
+
+ \snippet code/src_corelib_text_qstring.cpp 4bis
+
Applications that define \l QT_NO_CAST_FROM_ASCII (as explained
in the QString documentation) don't have access to QString's
\c{const char *} API. To provide an efficient way of specifying
@@ -10247,10 +10277,10 @@ QDataStream &operator<<(QDataStream &out, const QString &str)
if (!str.isNull() || out.version() < 3) {
if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
out.writeBytes(reinterpret_cast<const char *>(str.unicode()),
- static_cast<uint>(sizeof(QChar) * str.length()));
+ static_cast<uint>(sizeof(QChar) * str.size()));
} else {
- QVarLengthArray<char16_t> buffer(str.length());
- qbswap<sizeof(char16_t)>(str.constData(), str.length(), buffer.data());
+ QVarLengthArray<char16_t> buffer(str.size());
+ qbswap<sizeof(char16_t)>(str.constData(), str.size(), buffer.data());
out.writeBytes(reinterpret_cast<const char *>(buffer.data()),
static_cast<uint>(sizeof(char16_t) * buffer.size()));
}
@@ -10873,13 +10903,19 @@ qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re)
}
qsizetype count = 0;
qsizetype index = -1;
- qsizetype len = haystack.length();
+ qsizetype len = haystack.size();
while (index <= len - 1) {
QRegularExpressionMatch match = re.match(haystack, index + 1);
if (!match.hasMatch())
break;
- index = match.capturedStart();
count++;
+
+ // Search again, from the next character after the beginning of this
+ // capture. If the capture starts with a surrogate pair, both together
+ // count as "one character".
+ index = match.capturedStart();
+ if (index < len && haystack[index].isHighSurrogate())
+ ++index;
}
return count;
}
@@ -10900,7 +10936,7 @@ qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re)
QString QString::toHtmlEscaped() const
{
QString rich;
- const qsizetype len = length();
+ const qsizetype len = size();
rich.reserve(qsizetype(len * 1.1));
for (QChar ch : *this) {
if (ch == u'<')
@@ -11040,16 +11076,6 @@ void QAbstractConcatenable::appendLatin1To(QLatin1StringView in, QChar *out) noe
qt_from_latin1(reinterpret_cast<char16_t *>(out), in.data(), size_t(in.size()));
}
-double QStringView::toDouble(bool *ok) const
-{
- return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator);
-}
-
-float QStringView::toFloat(bool *ok) const
-{
- return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);
-}
-
/*!
\fn template <typename T> qsizetype erase(QString &s, const T &t)
\relates QString
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 3f15001ff8..a0c546e1f5 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -105,7 +105,11 @@ public:
[[nodiscard]] inline QString arg(Args &&...args) const;
[[nodiscard]] constexpr QLatin1Char at(qsizetype i) const
- { return Q_ASSERT(i >= 0), Q_ASSERT(i < size()), QLatin1Char(m_data[i]); }
+ {
+ Q_ASSERT(i >= 0);
+ Q_ASSERT(i < size());
+ return QLatin1Char(m_data[i]);
+ }
[[nodiscard]] constexpr QLatin1Char operator[](qsizetype i) const { return at(i); }
[[nodiscard]] constexpr QLatin1Char front() const { return at(0); }
@@ -525,14 +529,11 @@ public:
QChar fillChar = u' ') const;
private:
template <typename T>
- struct is_convertible_to_view_or_qstring_helper
- : std::integral_constant<bool,
- std::is_convertible<T, QString>::value ||
- std::is_convertible<T, QStringView>::value ||
- std::is_convertible<T, QLatin1StringView>::value> {};
- template <typename T>
- struct is_convertible_to_view_or_qstring
- : is_convertible_to_view_or_qstring_helper<typename std::decay<T>::type> {};
+ using is_convertible_to_view_or_qstring = std::disjunction<
+ std::is_convertible<T, QString>,
+ std::is_convertible<T, QStringView>,
+ std::is_convertible<T, QLatin1StringView>
+ >;
public:
template <typename...Args>
[[nodiscard]]
@@ -678,20 +679,20 @@ public:
QString &insert(qsizetype i, QChar c);
QString &insert(qsizetype i, const QChar *uc, qsizetype len);
- inline QString &insert(qsizetype i, const QString &s) { return insert(i, s.constData(), s.length()); }
- inline QString &insert(qsizetype i, QStringView v) { return insert(i, v.data(), v.length()); }
+ inline QString &insert(qsizetype i, const QString &s) { return insert(i, s.constData(), s.size()); }
+ inline QString &insert(qsizetype i, QStringView v) { return insert(i, v.data(), v.size()); }
QString &insert(qsizetype i, QLatin1StringView s);
QString &append(QChar c);
QString &append(const QChar *uc, qsizetype len);
QString &append(const QString &s);
- inline QString &append(QStringView v) { return append(v.data(), v.length()); }
+ inline QString &append(QStringView v) { return append(v.data(), v.size()); }
QString &append(QLatin1StringView s);
inline QString &prepend(QChar c) { return insert(0, c); }
inline QString &prepend(const QChar *uc, qsizetype len) { return insert(0, uc, len); }
inline QString &prepend(const QString &s) { return insert(0, s); }
- inline QString &prepend(QStringView v) { return prepend(v.data(), v.length()); }
+ inline QString &prepend(QStringView v) { return prepend(v.data(), v.size()); }
inline QString &prepend(QLatin1StringView s) { return insert(0, s); }
inline QString &operator+=(QChar c) { return append(c); }
@@ -1192,7 +1193,7 @@ QString QLatin1StringView::toString() const { return *this; }
//
QString QStringView::toString() const
-{ return Q_ASSERT(size() == length()), QString(data(), length()); }
+{ return QString(data(), size()); }
qint64 QStringView::toLongLong(bool *ok, int base) const
{ return QString::toIntegral_helper<qint64>(*this, ok, base); }
@@ -1482,7 +1483,7 @@ inline QString QString::fromStdString(const std::string &s)
inline std::wstring QString::toStdWString() const
{
std::wstring str;
- str.resize(length());
+ str.resize(size());
str.resize(toWCharArray(str.data()));
return str;
}
@@ -1494,16 +1495,16 @@ inline QString QString::fromStdU16String(const std::u16string &s)
{ return fromUtf16(s.data(), qsizetype(s.size())); }
inline std::u16string QString::toStdU16String() const
-{ return std::u16string(reinterpret_cast<const char16_t*>(data()), length()); }
+{ return std::u16string(reinterpret_cast<const char16_t*>(data()), size()); }
inline QString QString::fromStdU32String(const std::u32string &s)
{ return fromUcs4(s.data(), qsizetype(s.size())); }
inline std::u32string QString::toStdU32String() const
{
- std::u32string u32str(length(), char32_t(0));
+ std::u32string u32str(size(), char32_t(0));
qsizetype len = toUcs4_helper(reinterpret_cast<const ushort *>(constData()),
- length(), reinterpret_cast<uint*>(&u32str[0]));
+ size(), reinterpret_cast<uint*>(&u32str[0]));
u32str.resize(len);
return u32str;
}
@@ -1520,9 +1521,9 @@ inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcep
{ return -s.compare(*this, cs); }
inline int QString::localeAwareCompare(QStringView s) const
-{ return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
+{ return localeAwareCompare_helper(constData(), size(), s.constData(), s.size()); }
inline int QString::localeAwareCompare(QStringView s1, QStringView s2)
-{ return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
+{ return localeAwareCompare_helper(s1.constData(), s1.size(), s2.constData(), s2.size()); }
inline int QStringView::localeAwareCompare(QStringView other) const
{ return QString::localeAwareCompare(*this, other); }
diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp
index 4c94de029e..04e70949dd 100644
--- a/src/corelib/text/qstringconverter.cpp
+++ b/src/corelib/text/qstringconverter.cpp
@@ -194,7 +194,7 @@ static inline const uchar *simdFindNonAscii(const uchar *src, const uchar *end,
#ifdef __AVX2__
// do 32 characters at a time
// (this is similar to simdTestMask in qstring.cpp)
- const __m256i mask = _mm256_set1_epi8(0x80);
+ const __m256i mask = _mm256_set1_epi8(char(0x80));
for ( ; end - src >= 32; src += 32) {
__m256i data = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(src));
if (_mm256_testz_si256(mask, data))
@@ -251,7 +251,7 @@ static inline const uchar *simdFindNonAscii(const uchar *src, const uchar *end,
// Compare only the US-ASCII beginning of [src8, end8) and [src16, end16)
// and advance src8 and src16 to the first character that could not be compared
-static void simdCompareAscii(const char8_t *&src8, const char8_t *end8, const char16_t *&src16, const char16_t *end16)
+static void simdCompareAscii(const qchar8_t *&src8, const qchar8_t *end8, const char16_t *&src16, const char16_t *end16)
{
int bitSpacing = 1;
qptrdiff len = qMin(end8 - src8, end16 - src16);
@@ -437,7 +437,7 @@ static inline const uchar *simdFindNonAscii(const uchar *src, const uchar *end,
return src;
}
-static void simdCompareAscii(const char8_t *&, const char8_t *, const char16_t *&, const char16_t *)
+static void simdCompareAscii(const qchar8_t *&, const qchar8_t *, const char16_t *&, const char16_t *)
{
}
#else
@@ -457,7 +457,7 @@ static inline const uchar *simdFindNonAscii(const uchar *src, const uchar *end,
return src;
}
-static void simdCompareAscii(const char8_t *&, const char8_t *, const char16_t *&, const char16_t *)
+static void simdCompareAscii(const qchar8_t *&, const qchar8_t *, const char16_t *&, const char16_t *)
{
}
#endif
@@ -505,7 +505,7 @@ char *QUtf8::convertFromUnicode(char *out, QStringView in, QStringConverter::Sta
{
Q_ASSERT(state);
const QChar *uc = in.data();
- qsizetype len = in.length();
+ qsizetype len = in.size();
if (!len)
return out;
@@ -808,7 +808,7 @@ QUtf8::ValidUtf8Result QUtf8::isValidUtf8(QByteArrayView in)
int QUtf8::compareUtf8(QByteArrayView utf8, QStringView utf16) noexcept
{
- auto src1 = reinterpret_cast<const char8_t *>(utf8.data());
+ auto src1 = reinterpret_cast<const qchar8_t *>(utf8.data());
auto end1 = src1 + utf8.size();
auto src2 = reinterpret_cast<const char16_t *>(utf16.data());
auto end2 = src2 + utf16.size();
@@ -878,7 +878,7 @@ QByteArray QUtf16::convertFromUnicode(QStringView in, QStringConverter::State *s
QByteArray d(length, Qt::Uninitialized);
char *end = convertFromUnicode(d.data(), in, state, endian);
- Q_ASSERT(end - d.constData() == d.length());
+ Q_ASSERT(end - d.constData() == d.size());
Q_UNUSED(end);
return d;
}
@@ -901,13 +901,13 @@ char *QUtf16::convertFromUnicode(char *out, QStringView in, QStringConverter::St
out += 2;
}
if (endian == BigEndianness)
- qToBigEndian<char16_t>(in.data(), in.length(), out);
+ qToBigEndian<char16_t>(in.data(), in.size(), out);
else
- qToLittleEndian<char16_t>(in.data(), in.length(), out);
+ qToLittleEndian<char16_t>(in.data(), in.size(), out);
state->remainingChars = 0;
state->internalState |= HeaderDone;
- return out + 2*in.length();
+ return out + 2*in.size();
}
QString QUtf16::convertToUnicode(QByteArrayView in, QStringConverter::State *state, DataEndianness endian)
@@ -1037,7 +1037,7 @@ char *QUtf32::convertFromUnicode(char *out, QStringView in, QStringConverter::St
}
const QChar *uc = in.data();
- const QChar *end = in.data() + in.length();
+ const QChar *end = in.data() + in.size();
QChar ch;
char32_t ucs4;
if (state->remainingChars == 1) {
@@ -1219,7 +1219,7 @@ static QString convertToUnicodeCharByChar(QByteArrayView in, QStringConverter::S
QString s;
while ((next = CharNextExA(CP_ACP, mb, 0)) != mb) {
wchar_t wc[2] ={0};
- int charlength = next - mb;
+ int charlength = int(next - mb); // always just a few bytes
int len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, mb, charlength, wc, 2);
if (len>0) {
s.append(QChar(wc[0]));
@@ -1475,7 +1475,7 @@ static char *toLatin1(char *out, QStringView in, QStringConverter::State *state)
const char replacement = (state && state->flags & QStringConverter::Flag::ConvertInvalidToNull) ? 0 : '?';
qsizetype invalid = 0;
- for (qsizetype i = 0; i < in.length(); ++i) {
+ for (qsizetype i = 0; i < in.size(); ++i) {
if (in[i] > QChar(0xff)) {
*out = replacement;
++invalid;
@@ -1492,15 +1492,15 @@ static char *toLatin1(char *out, QStringView in, QStringConverter::State *state)
static QChar *fromLocal8Bit(QChar *out, QByteArrayView in, QStringConverter::State *state)
{
QString s = QLocal8Bit::convertToUnicode(in, state);
- memcpy(out, s.constData(), s.length()*sizeof(QChar));
- return out + s.length();
+ memcpy(out, s.constData(), s.size()*sizeof(QChar));
+ return out + s.size();
}
static char *toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
{
QByteArray s = QLocal8Bit::convertFromUnicode(in, state);
- memcpy(out, s.constData(), s.length());
- return out + s.length();
+ memcpy(out, s.constData(), s.size());
+ return out + s.size();
}
@@ -1751,7 +1751,7 @@ struct QStringConverterICU : QStringConverter
auto source = reinterpret_cast<const UChar *>(in.data());
auto sourceLimit = reinterpret_cast<const UChar *>(in.data() + in.size());
- qsizetype length = UCNV_GET_MAX_BYTES_FOR_STRING(in.length(), ucnv_getMaxCharSize(icu_conv));
+ qsizetype length = UCNV_GET_MAX_BYTES_FOR_STRING(in.size(), ucnv_getMaxCharSize(icu_conv));
char *target = out;
char *targetLimit = out + length;
@@ -1991,7 +1991,7 @@ const char *QStringConverter::name() const noexcept
*/
std::optional<QStringConverter::Encoding> QStringConverter::encodingForName(const char *name) noexcept
{
- for (int i = 0; i < LastEncoding + 1; ++i) {
+ for (qsizetype i = 0; i < LastEncoding + 1; ++i) {
if (nameMatch(encodingInterfaces[i].name, name))
return QStringConverter::Encoding(i);
}
@@ -2059,7 +2059,7 @@ static QByteArray parseHtmlMetaForEncoding(QByteArrayView data)
if (pos != -1) {
pos = charsetSearcher.indexIn(header, pos);
if (pos != -1) {
- pos += int(qstrlen("charset="));
+ pos += qstrlen("charset=");
if (pos < header.size() && (header.at(pos) == '\"' || header.at(pos) == '\''))
++pos;
diff --git a/src/corelib/text/qstringconverter_base.h b/src/corelib/text/qstringconverter_base.h
index 68900da8f0..bf464cbb6f 100644
--- a/src/corelib/text/qstringconverter_base.h
+++ b/src/corelib/text/qstringconverter_base.h
@@ -129,7 +129,7 @@ protected:
: iface(nullptr)
{}
constexpr explicit QStringConverter(Encoding encoding, Flags f)
- : iface(&encodingInterfaces[int(encoding)]), state(f)
+ : iface(&encodingInterfaces[qsizetype(encoding)]), state(f)
{}
constexpr explicit QStringConverter(const Interface *i) noexcept
: iface(i)
diff --git a/src/corelib/text/qstringconverter_p.h b/src/corelib/text/qstringconverter_p.h
index 7533e094a9..e801272646 100644
--- a/src/corelib/text/qstringconverter_p.h
+++ b/src/corelib/text/qstringconverter_p.h
@@ -24,7 +24,9 @@
QT_BEGIN_NAMESPACE
#ifndef __cpp_char8_t
-enum char8_t : uchar {};
+enum qchar8_t : uchar {};
+#else
+using qchar8_t = char8_t;
#endif
struct QUtf8BaseTraits
@@ -38,25 +40,25 @@ struct QUtf8BaseTraits
static void appendByte(uchar *&ptr, uchar b)
{ *ptr++ = b; }
- static void appendByte(char8_t *&ptr, char8_t b)
+ static void appendByte(qchar8_t *&ptr, qchar8_t b)
{ *ptr++ = b; }
static uchar peekByte(const uchar *ptr, qsizetype n = 0)
{ return ptr[n]; }
- static uchar peekByte(const char8_t *ptr, qsizetype n = 0)
+ static uchar peekByte(const qchar8_t *ptr, qsizetype n = 0)
{ return ptr[n]; }
static qptrdiff availableBytes(const uchar *ptr, const uchar *end)
{ return end - ptr; }
- static qptrdiff availableBytes(const char8_t *ptr, const char8_t *end)
+ static qptrdiff availableBytes(const qchar8_t *ptr, const qchar8_t *end)
{ return end - ptr; }
static void advanceByte(const uchar *&ptr, qsizetype n = 1)
{ ptr += n; }
- static void advanceByte(const char8_t *&ptr, qsizetype n = 1)
+ static void advanceByte(const qchar8_t *&ptr, qsizetype n = 1)
{ ptr += n; }
static void appendUtf16(char16_t *&ptr, char16_t uc)
@@ -304,6 +306,7 @@ struct Q_CORE_EXPORT QLocal8Bit
static int checkUtf8();
static bool isUtf8()
{
+ Q_CONSTINIT
static QBasicAtomicInteger<qint8> result = { 0 };
int r = result.loadRelaxed();
if (r == 0) {
diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp
index 8eb730ee02..347a89cfa9 100644
--- a/src/corelib/text/qstringlist.cpp
+++ b/src/corelib/text/qstringlist.cpp
@@ -84,25 +84,7 @@ QT_BEGIN_NAMESPACE
\section1 Iterating Over the Strings
- To iterate over a list, you can either use index positions or
- QList's Java-style and STL-style iterator types:
-
- Indexing:
-
- \snippet qstringlist/main.cpp 1
-
- Java-style iterator:
-
- \snippet qstringlist/main.cpp 2
-
- STL-style iterator:
-
- \snippet qstringlist/main.cpp 3
-
- The QStringListIterator class is simply a type definition for
- QListIterator<QString>. QStringList also provide the
- QMutableStringListIterator class which is a type definition for
- QMutableListIterator<QString>.
+ See \l {Iterating over Containers}.
\section1 Manipulating the Strings
@@ -387,7 +369,7 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView befo
QStringView after, Qt::CaseSensitivity cs)
{
for (qsizetype i = 0; i < that->size(); ++i)
- (*that)[i].replace(before.data(), before.length(), after.data(), after.length(), cs);
+ (*that)[i].replace(before.data(), before.size(), after.data(), after.size(), cs);
}
#if QT_CONFIG(regularexpression)
@@ -492,7 +474,7 @@ QString QtPrivate::QStringList_join(const QStringList &list, QLatin1StringView s
*/
QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep)
{
- return QStringList_join(that, sep.data(), sep.length());
+ return QStringList_join(that, sep.data(), sep.size());
}
/*!
diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h
index 079f156479..31e4cf6dc9 100644
--- a/src/corelib/text/qstringlist.h
+++ b/src/corelib/text/qstringlist.h
@@ -87,7 +87,7 @@ public:
}
inline QString join(const QString &sep) const
- { return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); }
+ { return QtPrivate::QStringList_join(self(), sep.constData(), sep.size()); }
inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
{ return QtPrivate::QStringList_filter(self(), str, cs); }
inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp
index c13b51b493..8f1aa3dfea 100644
--- a/src/corelib/text/qstringview.cpp
+++ b/src/corelib/text/qstringview.cpp
@@ -32,7 +32,7 @@ QT_BEGIN_NAMESPACE
When used as an interface type, QStringView allows a single function to accept
a wide variety of UTF-16 string data sources. One function accepting QStringView
thus replaces three function overloads (taking QString and
- \c{(const QChar*, int)}), while at the same time enabling even more string data
+ \c{(const QChar*, qsizetype)}), while at the same time enabling even more string data
sources to be passed to the function, such as \c{u"Hello World"}, a \c char16_t
string literal.
@@ -481,7 +481,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn int QStringView::length() const
+ \fn QStringView::length() const
Same as size().
diff --git a/src/corelib/text/qt_attribution.json b/src/corelib/text/qt_attribution.json
index 3d633b7390..662d2f51cf 100644
--- a/src/corelib/text/qt_attribution.json
+++ b/src/corelib/text/qt_attribution.json
@@ -24,7 +24,7 @@
"QDocModule": "qtcore",
"QtUsage": "Used in Qt Core (QTimeZone, QLocale).",
"Files": "For update, see qtbase/util/locale_database/cldr2qlocalexml.py",
- "Files": "qlocale_data_p.h qtimezoneprivate_data_p.h",
+ "Files": "qlocale_data_p.h ../time/qtimezoneprivate_data_p.h",
"Description": "The Unicode CLDR provides key building blocks for software to support the
world's languages, with the largest and most extensive standard repository of locale data
diff --git a/src/corelib/text/qtextboundaryfinder.cpp b/src/corelib/text/qtextboundaryfinder.cpp
index e387df3f8d..8f20967a1d 100644
--- a/src/corelib/text/qtextboundaryfinder.cpp
+++ b/src/corelib/text/qtextboundaryfinder.cpp
@@ -20,7 +20,7 @@ static void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharA
case QTextBoundaryFinder::Line: options |= QUnicodeTools::LineBreaks; break;
default: break;
}
- QUnicodeTools::initCharAttributes(str, scriptItems.data(), scriptItems.count(), attributes, options);
+ QUnicodeTools::initCharAttributes(str, scriptItems.data(), scriptItems.size(), attributes, options);
}
/*!
@@ -213,7 +213,7 @@ QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, QStringView string,
, attributes(nullptr)
{
if (!sv.isEmpty()) {
- if (buffer && (uint)bufferSize >= (sv.size() + 1) * sizeof(QCharAttributes)) {
+ if (buffer && bufferSize / int(sizeof(QCharAttributes)) >= sv.size() + 1) {
attributes = reinterpret_cast<QCharAttributes *>(buffer);
freeBuffer = false;
} else {
diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp
index beef159daa..32e791563f 100644
--- a/src/corelib/text/qunicodetools.cpp
+++ b/src/corelib/text/qunicodetools.cpp
@@ -3,12 +3,15 @@
#include "qunicodetools_p.h"
+#include "qmutex.h"
#include "qunicodetables_p.h"
#include "qvarlengtharray.h"
#if QT_CONFIG(library)
#include "qlibrary.h"
#endif
+#include <mutex>
+
#include <limits.h>
#define FLAG(x) (1 << (x))
@@ -17,7 +20,12 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-Q_AUTOTEST_EXPORT int qt_initcharattributes_default_algorithm_only = 0;
+#ifdef QT_BUILD_INTERNAL
+Q_CONSTINIT Q_AUTOTEST_EXPORT
+#else
+constexpr
+#endif
+int qt_initcharattributes_default_algorithm_only = 0;
namespace QUnicodeTools {
@@ -254,7 +262,6 @@ static void getWordBreaks(const char16_t *string, qsizetype len, QCharAttributes
const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4);
QUnicodeTables::WordBreakClass ncls = (QUnicodeTables::WordBreakClass) prop->wordBreakClass;
-#ifdef QT_BUILD_INTERNAL
if (qt_initcharattributes_default_algorithm_only) {
// as of Unicode 5.1, some punctuation marks were mapped to MidLetter and MidNumLet
// which caused "hi.there" to be treated like if it were just a single word;
@@ -265,7 +272,6 @@ static void getWordBreaks(const char16_t *string, qsizetype len, QCharAttributes
else if (ucs4 == 0x003A) // COLON
ncls = QUnicodeTables::WordBreak_MidLetter;
}
-#endif
uchar action = WB::breakTable[cls][ncls];
switch (action) {
@@ -1263,12 +1269,12 @@ static inline Form form(unsigned short uc) {
static qsizetype indic_nextSyllableBoundary(QChar::Script script, const char16_t *s, qsizetype start, qsizetype end, bool *invalid)
{
*invalid = false;
- IDEBUG("indic_nextSyllableBoundary: start=%d, end=%d", int(start), int(end));
+ IDEBUG("indic_nextSyllableBoundary: start=%lld, end=%lld", qlonglong(start), qlonglong(end));
const char16_t *uc = s+start;
qsizetype pos = 0;
Form state = form(uc[pos]);
- IDEBUG("state[%d]=%d (uc=%4x)", int(pos), state, uc[pos]);
+ IDEBUG("state[%lld]=%d (uc=%4x)", qlonglong(pos), state, uc[pos]);
pos++;
if (state != Consonant && state != IndependentVowel) {
@@ -1279,7 +1285,7 @@ static qsizetype indic_nextSyllableBoundary(QChar::Script script, const char16_t
while (pos < end - start) {
Form newState = form(uc[pos]);
- IDEBUG("state[%d]=%d (uc=%4x)", int(pos), newState, uc[pos]);
+ IDEBUG("state[%lld]=%d (uc=%4x)", qlonglong(pos), newState, uc[pos]);
switch (newState) {
case Control:
newState = state;
@@ -1405,11 +1411,15 @@ Q_CONSTINIT static th_next_cell_def th_next_cell = nullptr;
static int init_libthai() {
#if QT_CONFIG(library)
- Q_CONSTINIT static bool initialized = false;
- if (!initialized && (!th_brk || !th_next_cell)) {
- th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve("thai"_L1, static_cast<int>(LIBTHAI_MAJOR), "th_brk"));
- th_next_cell = (th_next_cell_def)QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_next_cell");
- initialized = true;
+ Q_CONSTINIT static QBasicAtomicInt initialized = Q_BASIC_ATOMIC_INITIALIZER(false);
+ Q_CONSTINIT static QBasicMutex mutex;
+ if (!initialized.loadAcquire()) {
+ const auto locker = std::scoped_lock(mutex);
+ if (!initialized.loadAcquire()) {
+ th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_brk"));
+ th_next_cell = (th_next_cell_def)QLibrary::resolve("thai"_L1, LIBTHAI_MAJOR, "th_next_cell");
+ initialized.storeRelease(true);
+ }
}
if (th_brk && th_next_cell)
return 1;
@@ -1444,8 +1454,8 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
char *cstr = s;
int *break_positions = nullptr;
int brp[128];
- int brp_size = 0;
- qsizetype numbreaks, i, j, cell_length;
+ size_t brp_size = 0;
+ qsizetype numbreaks, i;
struct thcell_t tis_cell;
if (!init_libthai())
@@ -1466,7 +1476,7 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
if (len > 128) {
break_positions = static_cast<int *>(malloc (sizeof(int) * len));
memset (break_positions, 0, sizeof(int) * len);
- brp_size = len;
+ brp_size = size_t(len);
}
else {
break_positions = brp;
@@ -1494,11 +1504,12 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
/* manage grapheme boundaries */
i = 0;
while (i < len) {
- cell_length = static_cast<uint>(th_next_cell(reinterpret_cast<const unsigned char *>(cstr) + i, len - i, &tis_cell, true));
+ size_t cell_length = th_next_cell(reinterpret_cast<const unsigned char *>(cstr) + i,
+ size_t(len - i), &tis_cell, true);
attributes[i].graphemeBoundary = true;
- for (j = 1; j < cell_length; j++)
+ for (size_t j = 1; j < cell_length; ++j)
attributes[i + j].graphemeBoundary = false;
i += cell_length;
@@ -1825,7 +1836,7 @@ static qsizetype myanmar_nextSyllableBoundary(const char16_t *s, qsizetype start
if (pos == start)
*invalid = (bool)(charClass & Mymr_CF_DOTTED_CIRCLE);
- MMDEBUG("state[%d]=%d class=%8x (uc=%4x)", int(pos - start), state, charClass, *uc);
+ MMDEBUG("state[%lld]=%d class=%8x (uc=%4x)", qlonglong(pos - start), state, charClass, *uc);
if (state < 0) {
if (state < -1)
@@ -2160,7 +2171,7 @@ static qsizetype khmer_nextSyllableBoundary(const char16_t *s, qsizetype start,
}
state = khmerStateTable[state][charClass & CF_CLASS_MASK];
- KHDEBUG("state[%d]=%d class=%8lx (uc=%4x)", int(pos - start), state,
+ KHDEBUG("state[%lld]=%d class=%8lx (uc=%4x)", qlonglong(pos - start), state,
charClass, *uc );
if (state < 0) {
diff --git a/src/corelib/text/qutf8stringview.qdoc b/src/corelib/text/qutf8stringview.qdoc
index ae80a5de40..e19e451f99 100644
--- a/src/corelib/text/qutf8stringview.qdoc
+++ b/src/corelib/text/qutf8stringview.qdoc
@@ -473,7 +473,7 @@
*/
/*!
- \fn int QUtf8StringView::length() const
+ \fn QUtf8StringView::length() const
Same as size().
diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp
index 0184774b44..210218d72d 100644
--- a/src/corelib/thread/qatomic.cpp
+++ b/src/corelib/thread/qatomic.cpp
@@ -397,14 +397,21 @@
Atomic test-and-set.
+ \note If you use this function in a loop, consider using the overload with the
+ additional \c{T &currentValue} argument instead, which avoids the extra load() on
+ failure.
+
If the current value of this QAtomicInteger is the \a expectedValue,
the test-and-set functions assign the \a newValue to this
QAtomicInteger and return true. If the values are \e not the same,
this function does nothing and returns \c false.
+//![memory-order-relaxed]
This function uses \e relaxed \l {QAtomicInteger#Memory
ordering}{memory ordering} semantics, leaving the compiler and
processor to freely reorder memory accesses.
+//![memory-order-relaxed]
+
*/
/*!
@@ -412,15 +419,21 @@
Atomic test-and-set.
+ \note If you use this function in a loop, consider using the overload with the
+ additional \c{T &currentValue} argument instead, which avoids the extra load() on
+ failure.
+
If the current value of this QAtomicInteger is the \a expectedValue,
the test-and-set functions assign the \a newValue to this
QAtomicInteger and return true. If the values are \e not the same,
this function does nothing and returns \c false.
+//![memory-order-acquire]
This function uses \e acquire \l {QAtomicInteger#Memory
ordering}{memory ordering} semantics, which ensures that memory
access following the atomic operation (in program order) may not
be re-ordered before the atomic operation.
+//![memory-order-acquire]
*/
/*!
@@ -428,15 +441,21 @@
Atomic test-and-set.
+ \note If you use this function in a loop, consider using the overload with the
+ additional \c{T &currentValue} argument instead, which avoids the extra load() on
+ failure.
+
If the current value of this QAtomicInteger is the \a expectedValue,
the test-and-set functions assign the \a newValue to this
QAtomicInteger and return true. If the values are \e not the same,
this function does nothing and returns \c false.
+//![memory-order-release]
This function uses \e release \l {QAtomicInteger#Memory
ordering}{memory ordering} semantics, which ensures that memory
access before the atomic operation (in program order) may not be
re-ordered after the atomic operation.
+//![memory-order-release]
*/
/*!
@@ -444,15 +463,78 @@
Atomic test-and-set.
+ \note If you use this function in a loop, consider using the overload with the
+ additional \c{T &currentValue} argument instead, which avoids the extra load() on
+ failure.
+
If the current value of this QAtomicInteger is the \a expectedValue,
the test-and-set functions assign the \a newValue to this
QAtomicInteger and return true. If the values are \e not the same,
this function does nothing and returns \c false.
+//![memory-order-ordered]
This function uses \e ordered \l {QAtomicInteger#Memory
ordering}{memory ordering} semantics, which ensures that memory
access before and after the atomic operation (in program order)
may not be re-ordered.
+//![memory-order-ordered]
+
+*/
+
+/*!
+ \fn template <typename T> bool QAtomicInteger<T>::testAndSetRelaxed(T expectedValue, T newValue, T &currentValue)
+ \since 5.3
+
+ Atomic test-and-set.
+
+ If the current value of this QAtomicInteger is the \a expectedValue, the
+ test-and-set functions assign the \a newValue to this QAtomicInteger and
+ return \c true. If the values are \e not the same, the functions load the
+ current value of this QAtomicInteger into \a currentValue and return \c false.
+
+ \include qatomic.cpp memory-order-relaxed
+*/
+
+/*!
+ \fn template <typename T> bool QAtomicInteger<T>::testAndSetAcquire(T expectedValue, T newValue, T &currentValue)
+ \since 5.3
+
+ Atomic test-and-set.
+
+ If the current value of this QAtomicInteger is the \a expectedValue, the
+ test-and-set functions assign the \a newValue to this QAtomicInteger and
+ return \c true. If the values are \e not the same, the functions load the
+ current value of this QAtomicInteger into \a currentValue and return \c false.
+
+ \include qatomic.cpp memory-order-acquire
+*/
+
+/*!
+ \fn template <typename T> bool QAtomicInteger<T>::testAndSetRelease(T expectedValue, T newValue, T &currentValue)
+ \since 5.3
+
+ Atomic test-and-set.
+
+ If the current value of this QAtomicInteger is the \a expectedValue, the
+ test-and-set functions assign the \a newValue to this QAtomicInteger and
+ return \c true. If the values are \e not the same, the functions loads the
+ current value of this QAtomicInteger into \a currentValue and return \c false.
+
+ \include qatomic.cpp memory-order-release
+*/
+
+/*!
+ \fn template <typename T> bool QAtomicInteger<T>::testAndSetOrdered(T expectedValue, T newValue, T &currentValue)
+ \since 5.3
+
+ Atomic test-and-set.
+
+ If the current value of this QAtomicInteger is the \a expectedValue, the
+ test-and-set functions assign the \a newValue to this QAtomicInteger and
+ return \c true. If the values are \e not the same, it loads the current
+ value of this QAtomicInteger into \a currentValue and return \c false.
+
+ \include qatomic.cpp memory-order-ordered
*/
/*!
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index a4c9c23fbe..b11e3f1bdf 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -70,6 +70,11 @@ public:
bool testAndSetRelease(T expectedValue, T newValue);
bool testAndSetOrdered(T expectedValue, T newValue);
+ bool testAndSetRelaxed(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetAcquire(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetRelease(T expectedValue, T newValue, T &currentValue);
+ bool testAndSetOrdered(T expectedValue, T newValue, T &currentValue);
+
static constexpr bool isFetchAndStoreNative();
static constexpr bool isFetchAndStoreWaitFree();
diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h
index 8e96b943ef..80aa3e8d7a 100644
--- a/src/corelib/thread/qfuture_impl.h
+++ b/src/corelib/thread/qfuture_impl.h
@@ -590,14 +590,14 @@ void Continuation<Function, ResultType, ParentResultType>::create(F &&func,
{
Q_ASSERT(f);
- auto continuation = [func = std::forward<F>(func), promise = QPromise(fi),
+ auto continuation = [func = std::forward<F>(func), fi,
context = QPointer<QObject>(context)](
const QFutureInterfaceBase &parentData) mutable {
Q_ASSERT(context);
const auto parent = QFutureInterface<ParentResultType>(parentData).future();
QMetaObject::invokeMethod(
context,
- [func = std::forward<F>(func), promise = std::move(promise), parent]() mutable {
+ [func = std::forward<F>(func), promise = QPromise(fi), parent]() mutable {
SyncContinuation<Function, ResultType, ParentResultType> continuationJob(
std::forward<Function>(func), parent, std::move(promise));
continuationJob.execute();
@@ -689,13 +689,13 @@ void FailureHandler<Function, ResultType>::create(F &&function, QFuture<ResultTy
Q_ASSERT(future);
auto failureContinuation =
- [function = std::forward<F>(function), promise = QPromise(fi),
+ [function = std::forward<F>(function), fi,
context = QPointer<QObject>(context)](const QFutureInterfaceBase &parentData) mutable {
Q_ASSERT(context);
const auto parent = QFutureInterface<ResultType>(parentData).future();
QMetaObject::invokeMethod(context,
[function = std::forward<F>(function),
- promise = std::move(promise), parent]() mutable {
+ promise = QPromise(fi), parent]() mutable {
FailureHandler<Function, ResultType> failureHandler(
std::forward<Function>(function), parent, std::move(promise));
failureHandler.run();
@@ -788,13 +788,13 @@ public:
QObject *context)
{
Q_ASSERT(future);
- auto canceledContinuation = [promise = QPromise(fi), handler = std::forward<F>(handler),
+ auto canceledContinuation = [fi, handler = std::forward<F>(handler),
context = QPointer<QObject>(context)](
const QFutureInterfaceBase &parentData) mutable {
Q_ASSERT(context);
auto parentFuture = QFutureInterface<ResultType>(parentData).future();
QMetaObject::invokeMethod(context,
- [promise = std::move(promise), parentFuture,
+ [promise = QPromise(fi), parentFuture,
handler = std::forward<F>(handler)]() mutable {
run(std::forward<F>(handler), parentFuture, std::move(promise));
});
diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp
index a82b7af873..ed46052fa7 100644
--- a/src/corelib/thread/qfutureinterface.cpp
+++ b/src/corelib/thread/qfutureinterface.cpp
@@ -105,6 +105,13 @@ void QFutureInterfaceBase::cancel(QFutureInterfaceBase::CancelMode mode)
break;
}
+ // Cancel the continuations chain
+ QFutureInterfaceBasePrivate *next = d->continuationData;
+ while (next) {
+ next->continuationState = QFutureInterfaceBasePrivate::Canceled;
+ next = next->continuationData;
+ }
+
d->waitCondition.wakeAll();
d->pausedWaitCondition.wakeAll();
@@ -719,7 +726,7 @@ void QFutureInterfaceBasePrivate::sendCallOut(const QFutureCallOutEvent &callOut
if (outputConnections.isEmpty())
return;
- for (int i = 0; i < outputConnections.count(); ++i)
+ for (int i = 0; i < outputConnections.size(); ++i)
outputConnections.at(i)->postCallOutEvent(callOutEvent);
}
@@ -729,7 +736,7 @@ void QFutureInterfaceBasePrivate::sendCallOuts(const QFutureCallOutEvent &callOu
if (outputConnections.isEmpty())
return;
- for (int i = 0; i < outputConnections.count(); ++i) {
+ for (int i = 0; i < outputConnections.size(); ++i) {
QFutureCallOutInterface *interface = outputConnections.at(i);
interface->postCallOutEvent(callOutEvent1);
interface->postCallOutEvent(callOutEvent2);
@@ -816,45 +823,56 @@ void QFutureInterfaceBase::setContinuation(std::function<void(const QFutureInter
{
QMutexLocker lock(&d->continuationMutex);
- if (continuationFutureData)
- continuationFutureData->parentData = d;
-
// If the state is ready, run continuation immediately,
// otherwise save it for later.
if (isFinished()) {
lock.unlock();
func(*this);
- } else {
+ lock.relock();
+ }
+ // Unless the continuation has been cleaned earlier, we have to
+ // store the move-only continuation, to guarantee that the associated
+ // future's data stays alive.
+ if (d->continuationState != QFutureInterfaceBasePrivate::Cleaned) {
d->continuation = std::move(func);
+ d->continuationData = continuationFutureData;
}
}
+void QFutureInterfaceBase::cleanContinuation()
+{
+ if (!d)
+ return;
+
+ QMutexLocker lock(&d->continuationMutex);
+ d->continuation = nullptr;
+ d->continuationState = QFutureInterfaceBasePrivate::Cleaned;
+ d->continuationData = nullptr;
+}
+
void QFutureInterfaceBase::runContinuation() const
{
QMutexLocker lock(&d->continuationMutex);
if (d->continuation) {
- auto fn = std::exchange(d->continuation, nullptr);
+ // Save the continuation in a local function, to avoid calling
+ // a null std::function below, in case cleanContinuation() is
+ // called from some other thread right after unlock() below.
+ auto fn = std::move(d->continuation);
lock.unlock();
fn(*this);
+
+ lock.relock();
+ // Unless the continuation has been cleaned earlier, we have to
+ // store the move-only continuation, to guarantee that the associated
+ // future's data stays alive.
+ if (d->continuationState != QFutureInterfaceBasePrivate::Cleaned)
+ d->continuation = std::move(fn);
}
}
bool QFutureInterfaceBase::isChainCanceled() const
{
- if (isCanceled())
- return true;
-
- auto parent = d->parentData;
- while (parent) {
- // If the future is in Canceled state because it had an exception, we want to
- // continue checking the chain of parents for cancellation, otherwise if the exception
- // is handled inside the chain, it won't be interrupted even though cancellation has
- // been requested.
- if ((parent->state.loadRelaxed() & Canceled) && !parent->hasException)
- return true;
- parent = parent->parentData;
- }
- return false;
+ return isCanceled() || d->continuationState == QFutureInterfaceBasePrivate::Canceled;
}
void QFutureInterfaceBase::setLaunchAsync(bool value)
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h
index 820faa9ec2..418f19866d 100644
--- a/src/corelib/thread/qfutureinterface.h
+++ b/src/corelib/thread/qfutureinterface.h
@@ -183,9 +183,7 @@ protected:
void setContinuation(std::function<void(const QFutureInterfaceBase &)> func);
void setContinuation(std::function<void(const QFutureInterfaceBase &)> func,
QFutureInterfaceBasePrivate *continuationFutureData);
-#if QT_CORE_REMOVED_SINCE(6, 4)
void cleanContinuation();
-#endif
void runContinuation() const;
void setLaunchAsync(bool value);
@@ -349,7 +347,7 @@ inline bool QFutureInterface<T>::reportResults(const QList<T> &_results, int beg
if (store.filterMode()) {
this->reportResultsReady(resultCountBefore, store.count());
} else {
- this->reportResultsReady(insertIndex, insertIndex + _results.count());
+ this->reportResultsReady(insertIndex, insertIndex + _results.size());
}
return true;
}
diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h
index ec3517bab3..6258e61de7 100644
--- a/src/corelib/thread/qfutureinterface_p.h
+++ b/src/corelib/thread/qfutureinterface_p.h
@@ -141,7 +141,10 @@ public:
QThreadPool *m_pool = nullptr;
// Wrapper for continuation
std::function<void(const QFutureInterfaceBase &)> continuation;
- QFutureInterfaceBasePrivate *parentData = nullptr;
+ QFutureInterfaceBasePrivate *continuationData = nullptr;
+
+ enum ContinuationState : quint8 { Default, Canceled, Cleaned };
+ std::atomic<ContinuationState> continuationState { Default };
RefCount refCount = 1;
QAtomicInt state; // reads and writes can happen unprotected, both must be atomic
diff --git a/src/corelib/thread/qfuturesynchronizer.h b/src/corelib/thread/qfuturesynchronizer.h
index 8b85e20038..2cf2ca1b76 100644
--- a/src/corelib/thread/qfuturesynchronizer.h
+++ b/src/corelib/thread/qfuturesynchronizer.h
@@ -38,12 +38,12 @@ public:
void waitForFinished()
{
if (m_cancelOnWait) {
- for (int i = 0; i < m_futures.count(); ++i) {
+ for (int i = 0; i < m_futures.size(); ++i) {
m_futures[i].cancel();
}
}
- for (int i = 0; i < m_futures.count(); ++i) {
+ for (int i = 0; i < m_futures.size(); ++i) {
m_futures[i].waitForFinished();
}
}
diff --git a/src/corelib/thread/qlocking_p.h b/src/corelib/thread/qlocking_p.h
index 0c205fff66..9fa7e70da9 100644
--- a/src/corelib/thread/qlocking_p.h
+++ b/src/corelib/thread/qlocking_p.h
@@ -8,10 +8,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of qmutex.cpp, qmutex_unix.cpp, and qmutex_win.cpp. This header
-// file may change from version to version without notice, or even be
-// removed.
+// This file is not part of the Qt API. It exists for the convenience of
+// qmutex.cpp and qmutex_unix.cpp. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp
index fb15606ec0..7b4aac9532 100644
--- a/src/corelib/thread/qmutex.cpp
+++ b/src/corelib/thread/qmutex.cpp
@@ -865,12 +865,10 @@ void QMutexPrivate::derefWaiters(int value) noexcept
QT_END_NAMESPACE
-#if defined(Q_OS_LINUX) && defined(QT_ALWAYS_USE_FUTEX)
+#if defined(QT_ALWAYS_USE_FUTEX)
// nothing
#elif defined(Q_OS_MAC)
# include "qmutex_mac.cpp"
-#elif defined(Q_OS_WIN)
-# include "qmutex_win.cpp"
#else
# include "qmutex_unix.cpp"
#endif
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 036fde729b..ce7b5275ac 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -9,10 +9,8 @@
#include <QtCore/qtsan_impl.h>
#include <new>
-#if __has_include(<chrono>)
-# include <chrono>
-# include <limits>
-#endif
+#include <chrono>
+#include <limits>
class tst_QMutex;
@@ -31,7 +29,6 @@ class QMutex;
class QRecursiveMutex;
class QMutexPrivate;
-#if __has_include(<chrono>)
namespace QtPrivate
{
template<class Rep, class Period>
@@ -57,7 +54,6 @@ namespace QtPrivate
return ms < maxInt ? int(ms) : maxInt;
}
}
-#endif
class Q_CORE_EXPORT QBasicMutex
{
diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h
index 9985a068c5..e5932d0a66 100644
--- a/src/corelib/thread/qmutex_p.h
+++ b/src/corelib/thread/qmutex_p.h
@@ -10,10 +10,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of qmutex.cpp, qmutex_unix.cpp, and qmutex_win.cpp. This header
-// file may change from version to version without notice, or even be
-// removed.
+// This file is not part of the Qt API. It exists for the convenience of
+// qmutex.cpp and qmutex_unix.cpp. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
@@ -90,8 +89,6 @@ public:
bool wakeup;
pthread_mutex_t mutex;
pthread_cond_t cond;
-#elif defined(Q_OS_WIN)
- Qt::HANDLE event;
#endif
};
diff --git a/src/corelib/thread/qmutex_win.cpp b/src/corelib/thread/qmutex_win.cpp
deleted file mode 100644
index 8c7741c113..0000000000
--- a/src/corelib/thread/qmutex_win.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-
-#include "qmutex.h"
-#include <qatomic.h>
-#include "qmutex_p.h"
-#include <qt_windows.h>
-
-QT_BEGIN_NAMESPACE
-
-QMutexPrivate::QMutexPrivate()
-{
- event = CreateEvent(0, FALSE, FALSE, 0);
-
- if (!event)
- qWarning("QMutexPrivate::QMutexPrivate: Cannot create event");
-}
-
-QMutexPrivate::~QMutexPrivate()
-{ CloseHandle(event); }
-
-bool QMutexPrivate::wait(int timeout)
-{
- return (WaitForSingleObjectEx(event, timeout < 0 ? INFINITE : timeout, FALSE) == WAIT_OBJECT_0);
-}
-
-void QMutexPrivate::wakeUp() noexcept
-{ SetEvent(event); }
-
-QT_END_NAMESPACE
diff --git a/src/corelib/thread/qpromise.h b/src/corelib/thread/qpromise.h
index d0f6e6ae66..43c30582be 100644
--- a/src/corelib/thread/qpromise.h
+++ b/src/corelib/thread/qpromise.h
@@ -41,6 +41,7 @@ public:
d.cancelAndFinish(); // cancel and finalize the state
d.runContinuation();
}
+ d.cleanContinuation();
}
// Core QPromise APIs
diff --git a/src/corelib/thread/qpromise.qdoc b/src/corelib/thread/qpromise.qdoc
index 09907c4e0e..a3af927e8d 100644
--- a/src/corelib/thread/qpromise.qdoc
+++ b/src/corelib/thread/qpromise.qdoc
@@ -38,6 +38,8 @@
\snippet snippet_qpromise.cpp multithread_init
\codeline
\snippet snippet_qpromise.cpp multithread_main
+ \codeline
+ \snippet snippet_qpromise.cpp multithread_cleanup
\sa QFuture
*/
diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h
index f633ed7801..af559b7a96 100644
--- a/src/corelib/thread/qresultstore.h
+++ b/src/corelib/thread/qresultstore.h
@@ -71,7 +71,7 @@ public:
template <typename T>
T *pointer()
{
- const T *p = qAsConst(*this).pointer<T>();
+ const T *p = std::as_const(*this).pointer<T>();
return const_cast<T *>(p);
}
@@ -164,23 +164,23 @@ public:
if (containsValidResultItem(index)) // reject if already present
return -1;
- return addResults(index, new QList<T>(*results), results->count(), results->count());
+ return addResults(index, new QList<T>(*results), results->size(), results->size());
}
template<typename T>
int addResults(int index, const QList<T> *results, int totalCount)
{
// reject if results are empty, and nothing is filtered away
- if ((m_filterMode == false || results->count() == totalCount) && results->empty())
+ if ((m_filterMode == false || results->size() == totalCount) && results->empty())
return -1;
if (containsValidResultItem(index)) // reject if already present
return -1;
- if (m_filterMode == true && results->count() != totalCount && 0 == results->count())
+ if (m_filterMode == true && results->size() != totalCount && 0 == results->size())
return addResults(index, nullptr, 0, totalCount);
- return addResults(index, new QList<T>(*results), results->count(), totalCount);
+ return addResults(index, new QList<T>(*results), results->size(), totalCount);
}
int addCanceledResult(int index)
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index 664085eb2b..803aa30bef 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -161,7 +161,7 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger<quintptr> &u, quintptr curValu
if constexpr (futexHasWaiterCount) {
Q_ASSERT(n > 1);
ptr = futexHigh32(&u);
- curValue >>= 32;
+ curValue = quint64(curValue) >> 32;
}
}
@@ -213,7 +213,8 @@ template <bool IsTimed> bool futexSemaphoreTryAcquire(QBasicAtomicInteger<quintp
if constexpr (futexHasWaiterCount) {
// We don't use the fetched value from above so futexWait() fails if
// it changed after the testAndSetOrdered above.
- if (((curValue >> 32) & 0x7fffffffU) == 0x7fffffffU) {
+ quint32 waiterCount = (quint64(curValue) >> 32) & 0x7fffffffU;
+ if (waiterCount == 0x7fffffffU) {
qCritical() << "Waiter count overflow in QSemaphore";
return false;
}
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index e294fe2fe0..e2f2707520 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -979,6 +979,16 @@ bool QThread::isRunning() const
return d->running;
}
+void QThread::requestInterruption()
+{
+
+}
+
+bool QThread::isInterruptionRequested() const
+{
+ return false;
+}
+
// No threads: so we can just use static variables
Q_CONSTINIT static QThreadData *data = nullptr;
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h
index 4cea76cf77..d856d8daa8 100644
--- a/src/corelib/thread/qthread.h
+++ b/src/corelib/thread/qthread.h
@@ -155,12 +155,12 @@ inline Qt::HANDLE QThread::currentThreadId() noexcept
Qt::HANDLE tid; // typedef to void*
static_assert(sizeof(tid) == sizeof(void*));
// See https://akkadia.org/drepper/tls.pdf for x86 ABI
-#if defined(Q_PROCESSOR_X86_32) && defined(Q_OS_LINUX) && defined(__GLIBC__) // x86 32-bit always uses GS
+#if defined(Q_PROCESSOR_X86_32) && ((defined(Q_OS_LINUX) && defined(__GLIBC__)) || defined(Q_OS_FREEBSD)) // x86 32-bit always uses GS
__asm__("movl %%gs:%c1, %0" : "=r" (tid) : "i" (2 * sizeof(void*)) : );
#elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_DARWIN64)
// 64bit macOS uses GS, see https://github.com/apple/darwin-xnu/blob/master/libsyscall/os/tsd.h
__asm__("movq %%gs:0, %0" : "=r" (tid) : : );
-#elif defined(Q_PROCESSOR_X86_64) && (defined(Q_OS_LINUX) && defined(__GLIBC__)) || defined(Q_OS_FREEBSD)
+#elif defined(Q_PROCESSOR_X86_64) && ((defined(Q_OS_LINUX) && defined(__GLIBC__)) || defined(Q_OS_FREEBSD))
// x86_64 Linux, BSD uses FS
__asm__("movq %%fs:%c1, %0" : "=r" (tid) : "i" (2 * sizeof(void*)) : );
#elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_WIN)
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index d7e5135199..777aa362b2 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -137,8 +137,7 @@ static void set_thread_data(QThreadData *data)
static void clear_thread_data()
{
- currentThreadData = nullptr;
- pthread_setspecific(current_thread_data_key, nullptr);
+ set_thread_data(nullptr);
}
template <typename T>
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index b1078dab18..51783321b9 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -188,7 +188,7 @@ inline bool comparePriority(int priority, const QueuePage *p)
void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
{
Q_ASSERT(runnable != nullptr);
- for (QueuePage *page : qAsConst(queue)) {
+ for (QueuePage *page : std::as_const(queue)) {
if (page->priority() == priority && !page->isFull()) {
page->push(runnable);
return;
@@ -200,9 +200,9 @@ void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
int QThreadPoolPrivate::activeThreadCount() const
{
- return (allThreads.count()
- - expiredThreads.count()
- - waitingThreads.count()
+ return (allThreads.size()
+ - expiredThreads.size()
+ - waitingThreads.size()
+ reservedThreads);
}
@@ -269,7 +269,7 @@ void QThreadPoolPrivate::reset()
mutex.unlock();
- for (QThreadPoolThread *thread : qAsConst(allThreadsCopy)) {
+ for (QThreadPoolThread *thread : std::as_const(allThreadsCopy)) {
if (thread->isRunning()) {
thread->runnableReady.wakeAll();
thread->wait();
@@ -348,7 +348,7 @@ bool QThreadPool::tryTake(QRunnable *runnable)
return false;
QMutexLocker locker(&d->mutex);
- for (QueuePage *page : qAsConst(d->queue)) {
+ for (QueuePage *page : std::as_const(d->queue)) {
if (page->tryTake(runnable)) {
if (page->isFinished()) {
d->queue.removeOne(page);
@@ -475,6 +475,21 @@ QThreadPool *QThreadPool::globalInstance()
}
/*!
+ Returns the QThreadPool instance for Qt Gui.
+ \internal
+*/
+QThreadPool *QThreadPoolPrivate::qtGuiInstance()
+{
+ Q_CONSTINIT static QPointer<QThreadPool> guiInstance;
+ Q_CONSTINIT static QBasicMutex theMutex;
+
+ const QMutexLocker locker(&theMutex);
+ if (guiInstance.isNull() && !QCoreApplication::closingDown())
+ guiInstance = new QThreadPool();
+ return guiInstance;
+}
+
+/*!
Reserves a thread and uses it to run \a runnable, unless this thread will
make the current thread count exceed maxThreadCount(). In that case,
\a runnable is added to a run queue instead. The \a priority argument can
@@ -590,12 +605,14 @@ bool QThreadPool::tryStart(std::function<void()> functionToRun)
int QThreadPool::expiryTimeout() const
{
Q_D(const QThreadPool);
+ QMutexLocker locker(&d->mutex);
return d->expiryTimeout;
}
void QThreadPool::setExpiryTimeout(int expiryTimeout)
{
Q_D(QThreadPool);
+ QMutexLocker locker(&d->mutex);
if (d->expiryTimeout == expiryTimeout)
return;
d->expiryTimeout = expiryTimeout;
@@ -616,6 +633,7 @@ void QThreadPool::setExpiryTimeout(int expiryTimeout)
int QThreadPool::maxThreadCount() const
{
Q_D(const QThreadPool);
+ QMutexLocker locker(&d->mutex);
return d->requestedMaxThreadCount;
}
@@ -685,12 +703,14 @@ void QThreadPool::reserveThread()
void QThreadPool::setStackSize(uint stackSize)
{
Q_D(QThreadPool);
+ QMutexLocker locker(&d->mutex);
d->stackSize = stackSize;
}
uint QThreadPool::stackSize() const
{
Q_D(const QThreadPool);
+ QMutexLocker locker(&d->mutex);
return d->stackSize;
}
@@ -711,12 +731,14 @@ uint QThreadPool::stackSize() const
void QThreadPool::setThreadPriority(QThread::Priority priority)
{
Q_D(QThreadPool);
+ QMutexLocker locker(&d->mutex);
d->threadPriority = priority;
}
QThread::Priority QThreadPool::threadPriority() const
{
Q_D(const QThreadPool);
+ QMutexLocker locker(&d->mutex);
return d->threadPriority;
}
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index f967880bde..67c703fabd 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -134,6 +134,8 @@ public:
void stealAndRunRunnable(QRunnable *runnable);
void deletePageIfFinished(QueuePage *page);
+ static QThreadPool *qtGuiInstance();
+
mutable QMutex mutex;
QSet<QThreadPoolThread *> allThreads;
QQueue<QThreadPoolThread *> waitingThreads;
diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp
index 55a603e0e6..c2029fe1b3 100644
--- a/src/corelib/thread/qthreadstorage.cpp
+++ b/src/corelib/thread/qthreadstorage.cpp
@@ -51,15 +51,15 @@ QThreadStorageData::QThreadStorageData(void (*func)(void *))
no where to store it, and no way to actually call it.
*/
QThreadData *data = QThreadData::current();
- id = data->tls.count();
+ id = data->tls.size();
DEBUG_MSG("QThreadStorageData: Allocated id %d, destructor %p cannot be stored", id, func);
return;
}
- for (id = 0; id < destr->count(); id++) {
+ for (id = 0; id < destr->size(); id++) {
if (destr->at(id) == nullptr)
break;
}
- if (id == destr->count()) {
+ if (id == destr->size()) {
destr->append(func);
} else {
(*destr)[id] = func;
diff --git a/src/corelib/thread/qwaitcondition.qdoc b/src/corelib/thread/qwaitcondition.qdoc
index bd3a675192..435771e1d8 100644
--- a/src/corelib/thread/qwaitcondition.qdoc
+++ b/src/corelib/thread/qwaitcondition.qdoc
@@ -98,10 +98,16 @@
/*!
\fn bool QWaitCondition::wait(QMutex *lockedMutex, unsigned long time)
\overload
+
+ Releases the \a lockedMutex and waits on the wait condition for \a time
+ milliseconds.
*/
/*!
\fn bool QWaitCondition::wait(QReadWriteLock *lockedReadWriteLock, unsigned long time)
\overload
+
+ Releases the \a lockedReadWriteLock and waits on the wait condition for \a
+ time milliseconds.
*/
/*!
diff --git a/src/corelib/thread/qwaitcondition_p.h b/src/corelib/thread/qwaitcondition_p.h
index e82f832817..0893e9dd35 100644
--- a/src/corelib/thread/qwaitcondition_p.h
+++ b/src/corelib/thread/qwaitcondition_p.h
@@ -7,10 +7,9 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of qmutex.cpp, qmutex_unix.cpp, and qmutex_win.cpp. This header
-// file may change from version to version without notice, or even be
-// removed.
+// This file is not part of the Qt API. It exists for the convenience of
+// qmutex.cpp and qmutex_unix.cpp. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
diff --git a/src/corelib/thread/qwaitcondition_win.cpp b/src/corelib/thread/qwaitcondition_win.cpp
index 0deef043cd..2152ae551f 100644
--- a/src/corelib/thread/qwaitcondition_win.cpp
+++ b/src/corelib/thread/qwaitcondition_win.cpp
@@ -178,7 +178,7 @@ void QWaitCondition::wakeOne()
{
// wake up the first waiting thread in the queue
QMutexLocker locker(&d->mtx);
- for (QWaitConditionEvent *current : qAsConst(d->queue)) {
+ for (QWaitConditionEvent *current : std::as_const(d->queue)) {
if (current->wokenUp)
continue;
SetEvent(current->event);
@@ -191,7 +191,7 @@ void QWaitCondition::wakeAll()
{
// wake up the all threads in the queue
QMutexLocker locker(&d->mtx);
- for (QWaitConditionEvent *current : qAsConst(d->queue)) {
+ for (QWaitConditionEvent *current : std::as_const(d->queue)) {
SetEvent(current->event);
current->wokenUp = true;
}
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 4135e60224..5ec745c772 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -122,7 +122,7 @@ static ParsedRfcDateTime rfcDateImpl(QStringView s)
QDate date;
const auto isShortName = [](QStringView name) {
- return (name.length() == 3 && name[0].isUpper()
+ return (name.size() == 3 && name[0].isUpper()
&& name[1].isLower() && name[2].isLower());
};
@@ -4947,7 +4947,7 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format)
// Documented as "ddd MMM d HH:mm:ss yyyy" with optional offset-suffix;
// and allow time either before or after year.
- if (parts.count() < 5 || it != tokens.end())
+ if (parts.size() < 5 || it != tokens.end())
return QDateTime();
// Year and time can be in either order.
@@ -4976,7 +4976,7 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format)
if (!time.isValid())
return QDateTime();
- if (parts.count() == 5)
+ if (parts.size() == 5)
return QDateTime(date, time, Qt::LocalTime);
QStringView tz = parts.at(5);
diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h
index 38438ad2e6..1fb401ebe9 100644
--- a/src/corelib/time/qdatetime.h
+++ b/src/corelib/time/qdatetime.h
@@ -253,18 +253,25 @@ class QDateTimePrivate;
class Q_CORE_EXPORT QDateTime
{
struct ShortData {
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- quintptr status : 8;
-#endif
#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
+# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ qint64 status : 8;
+# endif
qint64 msecs : 56;
+
+# if Q_BYTE_ORDER == Q_BIG_ENDIAN
+ qint64 status : 8;
+# endif
#else
+# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ quintptr status : 8;
+# endif
// note: this is only 24 bits on 32-bit systems...
qintptr msecs : sizeof(void *) * 8 - 8;
-#endif
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+# if Q_BYTE_ORDER == Q_BIG_ENDIAN
quintptr status : 8;
+# endif
#endif
};
@@ -448,7 +455,7 @@ public:
std::chrono::sys_time<std::chrono::milliseconds> toStdSysMilliseconds() const
{
const std::chrono::milliseconds duration(toMSecsSinceEpoch());
- return std::chrono::sys_time(duration);
+ return std::chrono::sys_time<std::chrono::milliseconds>(duration);
}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp
index 92c7899ac9..4e4cbdb9d6 100644
--- a/src/corelib/time/qtimezone.cpp
+++ b/src/corelib/time/qtimezone.cpp
@@ -742,7 +742,7 @@ QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime,
if (hasTransitions()) {
const QTimeZonePrivate::DataList plist = d->transitions(fromDateTime.toMSecsSinceEpoch(),
toDateTime.toMSecsSinceEpoch());
- list.reserve(plist.count());
+ list.reserve(plist.size());
for (const QTimeZonePrivate::Data &pdata : plist)
list.append(QTimeZonePrivate::toOffsetData(pdata));
}
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp
index b04f0f384f..5bdc4e2cc2 100644
--- a/src/corelib/time/qtimezoneprivate.cpp
+++ b/src/corelib/time/qtimezoneprivate.cpp
@@ -664,7 +664,7 @@ QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsI
QLocale::Territory territory)
{
const QList<QByteArray> list = windowsIdToIanaIds(windowsId, territory);
- return list.count() > 0 ? list.first() : QByteArray();
+ return list.size() > 0 ? list.first() : QByteArray();
}
QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windowsId)
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index 360f6636ed..e87e34f76d 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -357,7 +357,7 @@ static QDate calculatePosixDate(const QByteArray &dateRule, int year)
if (dateRule.at(0) == 'M') {
// nth week in month format "Mmonth.week.dow"
QList<QByteArray> dateParts = dateRule.split('.');
- if (dateParts.count() > 2) {
+ if (dateParts.size() > 2) {
int month = dateParts.at(0).mid(1).toInt(&ok);
int week = ok ? dateParts.at(1).toInt(&ok) : 0;
int dow = ok ? dateParts.at(2).toInt(&ok) : 0;
@@ -392,27 +392,28 @@ static int parsePosixTime(const char *begin, const char *end)
int hour, min = 0, sec = 0;
const int maxHour = 137; // POSIX's extended range.
- bool ok = false;
- const char *cut = begin;
- hour = qstrntoll(begin, end - begin, &cut, 10, &ok);
- if (!ok || hour < -maxHour || hour > maxHour || cut > begin + 2)
+ auto r = qstrntoll(begin, end - begin, 10);
+ hour = r.result;
+ if (!r.ok() || hour < -maxHour || hour > maxHour || r.endptr > begin + 2)
return INT_MIN;
- begin = cut;
+ begin = r.endptr;
if (begin < end && *begin == ':') {
// minutes
++begin;
- min = qstrntoll(begin, end - begin, &cut, 10, &ok);
- if (!ok || min < 0 || min > 59 || cut > begin + 2)
+ r = qstrntoll(begin, end - begin, 10);
+ min = r.result;
+ if (!r.ok() || min < 0 || min > 59 || r.endptr > begin + 2)
return INT_MIN;
- begin = cut;
+ begin = r.endptr;
if (begin < end && *begin == ':') {
// seconds
++begin;
- sec = qstrntoll(begin, end - begin, &cut, 10, &ok);
- if (!ok || sec < 0 || sec > 59 || cut > begin + 2)
+ r = qstrntoll(begin, end - begin, 10);
+ sec = r.result;
+ if (!r.ok() || sec < 0 || sec > 59 || r.endptr > begin + 2)
return INT_MIN;
- begin = cut;
+ begin = r.endptr;
}
}
@@ -527,7 +528,7 @@ static auto validatePosixRule(const QByteArray &posixRule)
// http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
// See also calculatePosixTransition()'s reference.
const auto parts = posixRule.split(',');
- const struct { bool isValid, hasDst; } fail{false, false}, good{true, parts.count() > 1};
+ const struct { bool isValid, hasDst; } fail{false, false}, good{true, parts.size() > 1};
const QByteArray &zoneinfo = parts.at(0);
if (zoneinfo.isEmpty())
return fail;
@@ -549,13 +550,13 @@ static auto validatePosixRule(const QByteArray &posixRule)
return fail;
if (good.hasDst) {
- if (parts.count() != 3 || parts.at(1).isEmpty() || parts.at(2).isEmpty())
+ if (parts.size() != 3 || parts.at(1).isEmpty() || parts.at(2).isEmpty())
return fail;
for (int i = 1; i < 3; ++i) {
const auto tran = parts.at(i).split('/');
if (!calculatePosixDate(tran.at(0), 1972).isValid())
return fail;
- if (tran.count() > 1) {
+ if (tran.size() > 1) {
const auto time = tran.at(1);
if (parsePosixTime(time.begin(), time.end()) == INT_MIN)
return fail;
@@ -596,7 +597,7 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
}
// If only the name part, or no DST specified, then no transitions
- if (parts.count() == 1 || !dstZone.hasValidOffset()) {
+ if (parts.size() == 1 || !dstZone.hasValidOffset()) {
QTimeZonePrivate::Data data;
data.atMSecsSinceEpoch = lastTranMSecs;
data.offsetFromUtc = stdZone.offset;
@@ -606,19 +607,19 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
result << data;
return result;
}
- if (parts.count() < 3 || parts.at(1).isEmpty() || parts.at(2).isEmpty())
+ if (parts.size() < 3 || parts.at(1).isEmpty() || parts.at(2).isEmpty())
return result; // Malformed.
// Get the std to dst transition details
const int twoOClock = 7200; // Default transition time, when none specified
const auto dstParts = parts.at(1).split('/');
const QByteArray dstDateRule = dstParts.at(0);
- const int dstTime = dstParts.count() < 2 ? twoOClock : parsePosixTransitionTime(dstParts.at(1));
+ const int dstTime = dstParts.size() < 2 ? twoOClock : parsePosixTransitionTime(dstParts.at(1));
// Get the dst to std transition details
const auto stdParts = parts.at(2).split('/');
const QByteArray stdDateRule = stdParts.at(0);
- const int stdTime = stdParts.count() < 2 ? twoOClock : parsePosixTransitionTime(stdParts.at(1));
+ const int stdTime = stdParts.size() < 2 ? twoOClock : parsePosixTransitionTime(stdParts.at(1));
if (dstDateRule.isEmpty() || stdDateRule.isEmpty() || dstTime == INT_MIN || stdTime == INT_MIN)
return result; // Malformed.
@@ -827,7 +828,7 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId)
// Offsets are stored as total offset, want to know separate UTC and DST offsets
// so find the first non-dst transition to use as base UTC Offset
int utcOffset = ret.m_preZoneRule.stdOffset;
- for (const QTzTransition &tran : qAsConst(tranList)) {
+ for (const QTzTransition &tran : std::as_const(tranList)) {
if (!typeList.at(tran.tz_typeind).tz_isdst) {
utcOffset = typeList.at(tran.tz_typeind).tz_gmtoff;
break;
@@ -835,7 +836,7 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId)
}
// Now for each transition time calculate and store our rule:
- const int tranCount = tranList.count();;
+ const int tranCount = tranList.size();;
ret.m_tranTimes.reserve(tranCount);
// The DST offset when in effect: usually stable, usually an hour:
int lastDstOff = 3600;
diff --git a/src/corelib/tools/qatomicscopedvaluerollback_p.h b/src/corelib/tools/qatomicscopedvaluerollback_p.h
index c802244d2e..a0f088ec45 100644
--- a/src/corelib/tools/qatomicscopedvaluerollback_p.h
+++ b/src/corelib/tools/qatomicscopedvaluerollback_p.h
@@ -4,6 +4,17 @@
#ifndef QATOMICSCOPEDVALUEROLLBACK_P_H
#define QATOMICSCOPEDVALUEROLLBACK_P_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtCore/qglobal.h>
#include <QtCore/qatomic.h>
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp
index e771877265..f63b0c5c59 100644
--- a/src/corelib/tools/qcommandlineparser.cpp
+++ b/src/corelib/tools/qcommandlineparser.cpp
@@ -500,9 +500,9 @@ QString QCommandLineParser::errorText() const
{
if (!d->errorText.isEmpty())
return d->errorText;
- if (d->unknownOptionNames.count() == 1)
+ if (d->unknownOptionNames.size() == 1)
return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());
- if (d->unknownOptionNames.count() > 1)
+ if (d->unknownOptionNames.size() > 1)
return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(QStringLiteral(", ")));
return QString();
}
@@ -691,7 +691,7 @@ bool QCommandLineParserPrivate::parse(const QStringList &args)
if (forcePositional) {
positionalArgumentList.append(argument);
} else if (argument.startsWith(doubleDashString)) {
- if (argument.length() > 2) {
+ if (argument.size() > 2) {
QString optionName = argument.mid(2).section(assignChar, 0, 0);
if (registerFoundOption(optionName)) {
if (!parseOptionValue(optionName, argument, &argumentIterator, args.end()))
@@ -793,7 +793,7 @@ bool QCommandLineParser::isSet(const QString &name) const
if (d->optionNames.contains(name))
return true;
const QStringList aliases = d->aliases(name);
- for (const QString &optionName : qAsConst(d->optionNames)) {
+ for (const QString &optionName : std::as_const(d->optionNames)) {
if (aliases.contains(optionName))
return true;
}
@@ -1042,7 +1042,7 @@ static QString wrapText(const QString &names, int optionNameMaxWidth, const QStr
int lastBreakable = -1;
const int max = 79 - (indentation.size() + optionNameMaxWidth + 1);
int x = 0;
- const int len = description.length();
+ const int len = description.size();
for (int i = 0; i < len; ++i) {
++x;
@@ -1110,13 +1110,13 @@ QString QCommandLineParserPrivate::helpText(bool includeQtOptions) const
QStringList optionNameList;
optionNameList.reserve(options.size());
int longestOptionNameString = 0;
- for (const QCommandLineOption &option : qAsConst(options)) {
+ for (const QCommandLineOption &option : std::as_const(options)) {
if (option.flags() & QCommandLineOption::HiddenFromHelp)
continue;
const QStringList optionNames = option.names();
QString optionNamesString;
for (const QString &optionName : optionNames) {
- const int numDashes = optionName.length() == 1 ? 1 : 2;
+ const int numDashes = optionName.size() == 1 ? 1 : 2;
optionNamesString += QLatin1StringView("--", numDashes) + optionName + ", "_L1;
}
if (!optionNames.isEmpty())
@@ -1125,12 +1125,12 @@ QString QCommandLineParserPrivate::helpText(bool includeQtOptions) const
if (!valueName.isEmpty())
optionNamesString += " <"_L1 + valueName + u'>';
optionNameList.append(optionNamesString);
- longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length());
+ longestOptionNameString = qMax(longestOptionNameString, optionNamesString.size());
}
++longestOptionNameString;
const int optionNameMaxWidth = qMin(50, longestOptionNameString);
auto optionNameIterator = optionNameList.cbegin();
- for (const QCommandLineOption &option : qAsConst(options)) {
+ for (const QCommandLineOption &option : std::as_const(options)) {
if (option.flags() & QCommandLineOption::HiddenFromHelp)
continue;
text += wrapText(*optionNameIterator, optionNameMaxWidth, option.description());
diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h
index 4a5f9f184f..fbd24a434b 100644
--- a/src/corelib/tools/qcontainertools_impl.h
+++ b/src/corelib/tools/qcontainertools_impl.h
@@ -62,6 +62,26 @@ void q_uninitialized_relocate_n(T* first, N n, T* out)
}
}
+/*!
+ \internal
+
+ A wrapper around std::rotate(), with an optimization for
+ Q_RELOCATABLE_TYPEs. We omit the return value, as it would be more work to
+ compute in the Q_RELOCATABLE_TYPE case and, unlike std::rotate on
+ ForwardIterators, callers can compute the result in constant time
+ themselves.
+*/
+template <typename T>
+void q_rotate(T *first, T *mid, T *last)
+{
+ if constexpr (QTypeInfo<T>::isRelocatable) {
+ const auto cast = [](T *p) { return reinterpret_cast<uchar*>(p); };
+ std::rotate(cast(first), cast(mid), cast(last));
+ } else {
+ std::rotate(first, mid, last);
+ }
+}
+
template<typename iterator, typename N>
void q_relocate_overlap_n_left_move(iterator first, N n, iterator d_first)
{
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 8d60be175e..063a15cdd9 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -4,6 +4,8 @@
#include <qcryptographichash.h>
#include <qiodevice.h>
+#include <qmutex.h>
+#include <private/qlocking_p.h>
#include "../../3rdparty/sha1/sha1.cpp"
@@ -164,7 +166,10 @@ public:
void reset() noexcept;
void addData(QByteArrayView bytes) noexcept;
- void finalize() noexcept;
+ // when not called from the static hash() function, this function needs to be
+ // called with finalizeMutex held:
+ void finalizeUnchecked() noexcept;
+ // END functions that need to be called with finalizeMutex held
QByteArrayView resultView() const noexcept { return result.toByteArrayView(); }
const QCryptographicHash::Algorithm method;
@@ -183,6 +188,7 @@ public:
#endif
};
#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
+#ifndef USING_OPENSSL30
enum class Sha3Variant
{
Sha3,
@@ -190,13 +196,13 @@ public:
};
void sha3Finish(int bitCount, Sha3Variant sha3Variant);
#endif
+#endif
class SmallByteArray {
- std::array<char, MaxHashLength> m_data;
+ std::array<quint8, MaxHashLength> m_data;
static_assert(MaxHashLength <= std::numeric_limits<std::uint8_t>::max());
- std::uint8_t m_size;
+ quint8 m_size;
public:
- char *data() noexcept { return m_data.data(); }
- const char *data() const noexcept { return m_data.data(); }
+ quint8 *data() noexcept { return m_data.data(); }
qsizetype size() const noexcept { return qsizetype{m_size}; }
bool isEmpty() const noexcept { return size() == 0; }
void clear() noexcept { m_size = 0; }
@@ -206,8 +212,10 @@ public:
m_size = std::uint8_t(s);
}
QByteArrayView toByteArrayView() const noexcept
- { return QByteArrayView{data(), size()}; }
+ { return QByteArrayView{m_data.data(), size()}; }
};
+ // protects result in finalize()
+ QBasicMutex finalizeMutex;
SmallByteArray result;
};
@@ -248,7 +256,7 @@ void QCryptographicHashPrivate::sha3Finish(int bitCount, Sha3Variant sha3Variant
break;
}
- sha3Final(&copy, reinterpret_cast<BitSequence *>(result.data()));
+ sha3Final(&copy, result.data());
}
#endif
@@ -539,21 +547,31 @@ QByteArray QCryptographicHash::result() const
*/
QByteArrayView QCryptographicHash::resultView() const noexcept
{
- d->finalize();
+ // resultView() is a const function, so concurrent calls are allowed; protect:
+ {
+ const auto lock = qt_scoped_lock(d->finalizeMutex);
+ // check that no other thread already finalizeUnchecked()'ed before us:
+ if (d->result.isEmpty())
+ d->finalizeUnchecked();
+ }
+ // resultView() remains(!) valid even after we dropped the mutex
return d->resultView();
}
-void QCryptographicHashPrivate::finalize() noexcept
-{
- if (!result.isEmpty())
- return;
+/*!
+ \internal
+ Must be called with finalizeMutex held (except from static hash() function,
+ where no sharing can take place).
+*/
+void QCryptographicHashPrivate::finalizeUnchecked() noexcept
+{
switch (method) {
case QCryptographicHash::Sha1: {
Sha1State copy = sha1Context;
result.resizeForOverwrite(20);
sha1FinalizeState(&copy);
- sha1ToHash(&copy, (unsigned char *)result.data());
+ sha1ToHash(&copy, result.data());
break;
}
#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
@@ -565,37 +583,37 @@ void QCryptographicHashPrivate::finalize() noexcept
case QCryptographicHash::Md4: {
md4_context copy = md4Context;
result.resizeForOverwrite(MD4_RESULTLEN);
- md4_final(&copy, (unsigned char *)result.data());
+ md4_final(&copy, result.data());
break;
}
case QCryptographicHash::Md5: {
MD5Context copy = md5Context;
result.resizeForOverwrite(16);
- MD5Final(&copy, (unsigned char *)result.data());
+ MD5Final(&copy, result.data());
break;
}
case QCryptographicHash::Sha224: {
SHA224Context copy = sha224Context;
result.resizeForOverwrite(SHA224HashSize);
- SHA224Result(&copy, reinterpret_cast<unsigned char *>(result.data()));
+ SHA224Result(&copy, result.data());
break;
}
case QCryptographicHash::Sha256: {
SHA256Context copy = sha256Context;
result.resizeForOverwrite(SHA256HashSize);
- SHA256Result(&copy, reinterpret_cast<unsigned char *>(result.data()));
+ SHA256Result(&copy, result.data());
break;
}
case QCryptographicHash::Sha384: {
SHA384Context copy = sha384Context;
result.resizeForOverwrite(SHA384HashSize);
- SHA384Result(&copy, reinterpret_cast<unsigned char *>(result.data()));
+ SHA384Result(&copy, result.data());
break;
}
case QCryptographicHash::Sha512: {
SHA512Context copy = sha512Context;
result.resizeForOverwrite(SHA512HashSize);
- SHA512Result(&copy, reinterpret_cast<unsigned char *>(result.data()));
+ SHA512Result(&copy, result.data());
break;
}
case QCryptographicHash::RealSha3_224:
@@ -619,7 +637,7 @@ void QCryptographicHashPrivate::finalize() noexcept
const auto length = hashLengthInternal(method);
blake2b_state copy = blake2bContext;
result.resizeForOverwrite(length);
- blake2b_final(&copy, reinterpret_cast<uint8_t *>(result.data()), length);
+ blake2b_final(&copy, result.data(), length);
break;
}
case QCryptographicHash::Blake2s_128:
@@ -629,7 +647,7 @@ void QCryptographicHashPrivate::finalize() noexcept
const auto length = hashLengthInternal(method);
blake2s_state copy = blake2sContext;
result.resizeForOverwrite(length);
- blake2s_final(&copy, reinterpret_cast<uint8_t *>(result.data()), length);
+ blake2s_final(&copy, result.data(), length);
break;
}
#endif
@@ -646,7 +664,7 @@ QByteArray QCryptographicHash::hash(QByteArrayView data, Algorithm method)
{
QCryptographicHashPrivate hash(method);
hash.addData(data);
- hash.finalize();
+ hash.finalizeUnchecked(); // no mutex needed: no-one but us has access to 'hash'
return hash.resultView().toByteArray();
}
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
index 9242a617ba..d8b3367de3 100644
--- a/src/corelib/tools/qeasingcurve.cpp
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -447,7 +447,7 @@ struct BezierEase : public QEasingCurveFunction
{
if (_bezierCurves.constLast() == QPointF(1.0, 1.0)) {
_init = true;
- _curveCount = _bezierCurves.count() / 3;
+ _curveCount = _bezierCurves.size() / 3;
for (int i=0; i < _curveCount; i++) {
_intervals[i] = _bezierCurves.at(i * 3 + 2).x();
@@ -466,17 +466,17 @@ struct BezierEase : public QEasingCurveFunction
_curves[0].p3y = _bezierCurves.at(2).y();
} else if (i == (_curveCount - 1)) {
- _curves[i].p0x = _bezierCurves.at(_bezierCurves.count() - 4).x();
- _curves[i].p0y = _bezierCurves.at(_bezierCurves.count() - 4).y();
+ _curves[i].p0x = _bezierCurves.at(_bezierCurves.size() - 4).x();
+ _curves[i].p0y = _bezierCurves.at(_bezierCurves.size() - 4).y();
- _curves[i].p1x = _bezierCurves.at(_bezierCurves.count() - 3).x();
- _curves[i].p1y = _bezierCurves.at(_bezierCurves.count() - 3).y();
+ _curves[i].p1x = _bezierCurves.at(_bezierCurves.size() - 3).x();
+ _curves[i].p1y = _bezierCurves.at(_bezierCurves.size() - 3).y();
- _curves[i].p2x = _bezierCurves.at(_bezierCurves.count() - 2).x();
- _curves[i].p2y = _bezierCurves.at(_bezierCurves.count() - 2).y();
+ _curves[i].p2x = _bezierCurves.at(_bezierCurves.size() - 2).x();
+ _curves[i].p2y = _bezierCurves.at(_bezierCurves.size() - 2).y();
- _curves[i].p3x = _bezierCurves.at(_bezierCurves.count() - 1).x();
- _curves[i].p3y = _bezierCurves.at(_bezierCurves.count() - 1).y();
+ _curves[i].p3x = _bezierCurves.at(_bezierCurves.size() - 1).x();
+ _curves[i].p3y = _bezierCurves.at(_bezierCurves.size() - 1).y();
} else {
_curves[i].p0x = _bezierCurves.at(i * 3 - 1).x();
_curves[i].p0y = _bezierCurves.at(i * 3 - 1).y();
@@ -535,7 +535,7 @@ struct BezierEase : public QEasingCurveFunction
qreal value(qreal x) override
{
- Q_ASSERT(_bezierCurves.count() % 3 == 0);
+ Q_ASSERT(_bezierCurves.size() % 3 == 0);
if (_bezierCurves.isEmpty()) {
return x;
@@ -869,7 +869,7 @@ struct TCBEase : public BezierEase
qreal value(qreal x) override
{
- Q_ASSERT(_bezierCurves.count() % 3 == 0);
+ Q_ASSERT(_bezierCurves.size() % 3 == 0);
if (_bezierCurves.isEmpty()) {
qWarning("QEasingCurve: Invalid tcb curve");
@@ -1274,7 +1274,7 @@ void QEasingCurve::addCubicBezierSegment(const QPointF & c1, const QPointF & c2,
QList<QPointF> static inline tcbToBezier(const TCBPoints &tcbPoints)
{
- const int count = tcbPoints.count();
+ const int count = tcbPoints.size();
QList<QPointF> bezierPoints;
bezierPoints.reserve(3 * (count - 1));
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 9b69c79389..8540b1bbb1 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -111,22 +111,18 @@ private:
#else
// can't use qEnvironmentVariableIntValue (reentrancy)
const char *seedstr = getenv("QT_HASH_SEED");
- const char *endptr = nullptr;
- bool ok = false;
- int seed = 0;
- if (seedstr)
- seed = qstrntoll(seedstr, strlen(seedstr), &endptr, 10, &ok);
- if (ok && endptr != seedstr + strlen(seedstr))
- ok = false;
- if (ok) {
- if (seed) {
- // can't use qWarning here (reentrancy)
- fprintf(stderr, "QT_HASH_SEED: forced seed value is not 0; ignored.\n");
+ if (seedstr) {
+ auto r = qstrntoll(seedstr, strlen(seedstr), 10);
+ if (r.endptr == seedstr + strlen(seedstr)) {
+ if (r.result) {
+ // can't use qWarning here (reentrancy)
+ fprintf(stderr, "QT_HASH_SEED: forced seed value is not 0; ignored.\n");
+ }
+
+ // we don't have to store to the seed, since it's pre-initialized by
+ // the compiler to zero
+ return result;
}
-
- // we don't have to store to the seed, since it's pre-initialized by
- // the compiler to zero
- return result;
}
// update the full seed
@@ -1683,10 +1679,15 @@ size_t qHash(long double key, size_t seed) noexcept
The two-arguments overloads take an unsigned integer that should be used to
seed the calculation of the hash function. This seed is provided by QHash
- in order to prevent a family of \l{algorithmic complexity attacks}. If both
- a one-argument and a two-arguments overload are defined for a key type,
- the latter is used by QHash (note that you can simply define a
- two-arguments version, and use a default value for the seed parameter).
+ in order to prevent a family of \l{algorithmic complexity attacks}.
+
+ \note In Qt 6 it is possible to define a \c{qHash()} overload
+ taking only one argument; support for this is deprecated. Starting
+ with Qt 7, it will be mandatory to use a two-arguments overload. If
+ both a one-argument and a two-arguments overload are defined for a
+ key type, the latter is used by QHash (note that you can simply
+ define a two-arguments version, and use a default value for the
+ seed parameter).
The second way to provide a hashing function is by specializing
the \c{std::hash} class for the key type \c{K}, and providing a
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 5075459531..952911f9dc 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -2121,7 +2121,7 @@ public:
{
const auto copy = isDetached() ? QMultiHash() : *this; // keep 'key' alive across the detach
detach();
- auto pair = qAsConst(*this).equal_range(key);
+ auto pair = std::as_const(*this).equal_range(key);
return qMakePair(iterator(pair.first.i), iterator(pair.second.i));
}
diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h
index c946cc61bc..c5fb1a768b 100644
--- a/src/corelib/tools/qhashfunctions.h
+++ b/src/corelib/tools/qhashfunctions.h
@@ -68,14 +68,6 @@ Q_DECL_CONST_FUNCTION constexpr size_t hash(size_t key, size_t seed) noexcept
}
}
-template <typename T, typename = void>
-constexpr inline bool HasQHashSingleArgOverload = false;
-
-template <typename T>
-constexpr inline bool HasQHashSingleArgOverload<T, std::enable_if_t<
- std::is_convertible_v<decltype(qHash(std::declval<const T &>())), size_t>
->> = true;
-
template <typename T1, typename T2> static constexpr bool noexceptPairHash();
}
@@ -141,6 +133,9 @@ Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed
{
return seed;
}
+template <class Enum, std::enable_if_t<std::is_enum_v<Enum>, bool> = true>
+Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(Enum e, size_t seed = 0) noexcept
+{ return QHashPrivate::hash(qToUnderlying(e), seed); }
// (some) Qt types
Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); }
@@ -168,9 +163,26 @@ template <typename Enum>
Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QFlags<Enum> flags, size_t seed = 0) noexcept
{ return qHash(flags.toInt(), seed); }
-template <typename T, std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T>, bool> = true>
+// ### Qt 7: remove this "catch-all" overload logic, and require users
+// to provide the two-argument version of qHash.
+#if (QT_VERSION < QT_VERSION_CHECK(7, 0, 0))
+// Beware of moving this code from here. It needs to see all the
+// declarations of qHash overloads for C++ fundamental types *before*
+// its own declaration.
+namespace QHashPrivate {
+template <typename T, typename = void>
+constexpr inline bool HasQHashSingleArgOverload = false;
+
+template <typename T>
+constexpr inline bool HasQHashSingleArgOverload<T, std::enable_if_t<
+ std::is_convertible_v<decltype(qHash(std::declval<const T &>())), size_t>
+>> = true;
+}
+
+template <typename T, std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T> && !std::is_enum_v<T>, bool> = true>
size_t qHash(const T &t, size_t seed) noexcept(noexcept(qHash(t)))
{ return qHash(t) ^ seed; }
+#endif // < Qt 7
template<typename T>
bool qHashEquals(const T &a, const T &b)
diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc
index e8e5a73596..f3b501a0e9 100644
--- a/src/corelib/tools/qlist.qdoc
+++ b/src/corelib/tools/qlist.qdoc
@@ -129,21 +129,7 @@
support \c operator==(). These requirements are documented on a
per-function basis.
- Like the other container classes, QList provides \l{Java-style iterators}
- (QListIterator and QMutableListIterator) and \l{STL-style iterators}
- (QList::const_iterator and QList::iterator). In practice, iterators are
- handy when working with generic algorithms provided by \l{generic
- algorithms}{Qt} and the C++ standard library. \l{Java-style iterators} are
- provided for backwards compatibility, prefer \l{STL-style iterators} when
- writing C++ code.
-
- \note Iterators over a QList, and references to individual elements
- within one, cannot be relied on to remain valid when any non-const method
- of the QList is called. Accessing such an iterator or reference after
- the call to a non-const method leads to undefined behavior. When stability
- for iterator-like functionality is required, you should use indexes instead
- of iterators as they are not tied to QList's internal state and thus do
- not get invalidated.
+ For iterating over the items, see \l {Iterating over Containers}.
In addition to QList, Qt also provides QVarLengthArray, a very
low-level class with little functionality that is optimized for
@@ -563,17 +549,14 @@
Removes all the elements from the list.
- \note Until Qt 5.6, this also released the memory used by
- the list. From Qt 5.7, the capacity is preserved. To shed
- all capacity, swap with a default-constructed list:
- \code
- QList<T> l ...;
- QList<T>().swap(l);
- Q_ASSERT(l.capacity() == 0);
- \endcode
- or call squeeze().
+ If this list is not shared, the capacity() is preserved. Use squeeze() to
+ shed excess capacity.
+
+ \note In Qt versions prior to 5.7 (for QVector) and 6.0 (for QList), this
+ function released the memory used by the list instead of preserving the
+ capacity.
- \sa squeeze()
+ \sa resize(), squeeze()
*/
/*! \fn template <typename T> const T &QList<T>::at(qsizetype i) const
diff --git a/src/corelib/tools/qmap.qdoc b/src/corelib/tools/qmap.qdoc
index 2e767acc4a..a08f4baa18 100644
--- a/src/corelib/tools/qmap.qdoc
+++ b/src/corelib/tools/qmap.qdoc
@@ -202,6 +202,15 @@
Returns an STL map equivalent to this QMap.
*/
+/*! \fn template <class Key, class T> std::map<Key, T> QMap<Key, T>::toStdMap() &&
+
+ \overload
+ \since 6.0
+
+ \note Calling this function will leave this QMap in the partially-formed state, in which
+ the only valid operations are destruction or assignment of a new value.
+*/
+
/*! \fn template <class Key, class T> bool QMap<Key, T>::operator==(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
Returns \c true if \a lhs is equal to \a rhs; otherwise returns
diff --git a/src/corelib/tools/qmessageauthenticationcode.cpp b/src/corelib/tools/qmessageauthenticationcode.cpp
index 4ff48fc822..5853e9951e 100644
--- a/src/corelib/tools/qmessageauthenticationcode.cpp
+++ b/src/corelib/tools/qmessageauthenticationcode.cpp
@@ -1,8 +1,11 @@
+// Copyright (C) 2023 The Qt Company Ltd.
// Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qmessageauthenticationcode.h"
#include "qvarlengtharray.h"
+#include "qmutex.h"
+#include "private/qlocking_p.h"
#include "qtcore-config_p.h"
@@ -70,11 +73,18 @@ public:
QByteArray key;
QByteArray result;
+ QBasicMutex finalizeMutex;
QCryptographicHash messageHash;
QCryptographicHash::Algorithm method;
bool messageHashInited;
void initMessageHash();
+ void finalize();
+
+ // when not called from the static hash() function, this function needs to be
+ // called with finalizeMutex held:
+ void finalizeUnchecked();
+ // END functions that need to be called with finalizeMutex held
};
void QMessageAuthenticationCodePrivate::initMessageHash()
@@ -208,27 +218,36 @@ bool QMessageAuthenticationCode::addData(QIODevice *device)
*/
QByteArray QMessageAuthenticationCode::result() const
{
- if (!d->result.isEmpty())
- return d->result;
+ d->finalize();
+ return d->result;
+}
- d->initMessageHash();
+void QMessageAuthenticationCodePrivate::finalize()
+{
+ const auto lock = qt_scoped_lock(finalizeMutex);
+ if (!result.isEmpty())
+ return;
+ initMessageHash();
+ finalizeUnchecked();
+}
- const int blockSize = qt_hash_block_size(d->method);
+void QMessageAuthenticationCodePrivate::finalizeUnchecked()
+{
+ const int blockSize = qt_hash_block_size(method);
- QByteArrayView hashedMessage = d->messageHash.resultView();
+ QByteArrayView hashedMessage = messageHash.resultView();
QVarLengthArray<char> oKeyPad(blockSize);
- const char * const keyData = d->key.constData();
+ const char * const keyData = key.constData();
for (int i = 0; i < blockSize; ++i)
oKeyPad[i] = keyData[i] ^ 0x5c;
- QCryptographicHash hash(d->method);
+ QCryptographicHash hash(method);
hash.addData(oKeyPad);
hash.addData(hashedMessage);
- d->result = hash.result();
- return d->result;
+ result = hash.result();
}
/*!
diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h
index a3b56badc6..461d61a2ba 100644
--- a/src/corelib/tools/qoffsetstringarray_p.h
+++ b/src/corelib/tools/qoffsetstringarray_p.h
@@ -20,6 +20,7 @@
#include <QByteArrayView>
+#include <QtCore/q20algorithm.h>
#include <array>
#include <limits>
#include <string_view>
@@ -69,21 +70,13 @@ private:
};
namespace QtPrivate {
-// std::copy is not constexpr in C++17
-template <typename II, typename OO>
-static constexpr OO copyData(II input, qsizetype n, OO output)
-{
- using E = decltype(+*output);
- for (qsizetype i = 0; i < n; ++i)
- output[i] = E(input[i]);
- return output + n;
-}
-
template <size_t Highest> constexpr auto minifyValue()
{
- if constexpr (Highest <= (std::numeric_limits<quint8>::max)()) {
+ constexpr size_t max8 = (std::numeric_limits<quint8>::max)();
+ constexpr size_t max16 = (std::numeric_limits<quint16>::max)();
+ if constexpr (Highest <= max8) {
return quint8(Highest);
- } else if constexpr (Highest <= (std::numeric_limits<quint16>::max)()) {
+ } else if constexpr (Highest <= max16) {
return quint16(Highest);
} else {
// int is probably enough for everyone
@@ -100,7 +93,7 @@ constexpr auto makeStaticString(Extractor extract, const T &... entries)
const char *strings[] = { extract(entries).operator const char *()... };
size_t lengths[] = { sizeof(extract(T{}))... };
for (size_t i = 0; i < std::size(strings); ++i) {
- copyData(strings[i], lengths[i], result.begin() + offset);
+ q20::copy_n(strings[i], lengths[i], result.begin() + offset);
offset += lengths[i];
}
return result;
@@ -110,7 +103,7 @@ template <size_t N> struct StaticString
{
char value[N] = {};
constexpr StaticString() = default;
- constexpr StaticString(const char (&s)[N]) { copyData(s, N, value); }
+ constexpr StaticString(const char (&s)[N]) { q20::copy_n(s, N, value); }
constexpr operator const char *() const { return value; }
};
@@ -136,7 +129,9 @@ constexpr auto qOffsetStringArray(StringExtractor extractString, const T &... en
// prepend zero
std::array<MinifiedOffsetType, Count + 1> minifiedOffsetList = {};
- QtPrivate::copyData(fullOffsetList.begin(), Count, minifiedOffsetList.begin() + 1);
+ q20::transform(fullOffsetList.begin(), fullOffsetList.end(),
+ minifiedOffsetList.begin() + 1,
+ [] (auto e) { return MinifiedOffsetType(e); });
std::array staticString = QtPrivate::makeStaticString<StringLength>(extractString, entries...);
return QOffsetStringArray(staticString, minifiedOffsetList);
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index 75efaed3cf..8070ca0175 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -22,9 +22,6 @@ constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2)
return std::make_pair(std::forward<T1>(value1), std::forward<T2>(value2));
}
-template<class T1, class T2>
-class QTypeInfo<std::pair<T1, T2>> : public QTypeInfoMerger<std::pair<T1, T2>, T1, T2> {};
-
QT_END_NAMESPACE
#endif // QPAIR_H
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index 2a945a31e8..a0f8d52c29 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -151,7 +151,7 @@ public:
// more Qt
typedef iterator Iterator;
typedef const_iterator ConstIterator;
- inline qsizetype count() const { return q_hash.count(); }
+ inline qsizetype count() const { return q_hash.size(); }
inline iterator insert(const T &value)
{ return q_hash.insert(value, QHashDummyValue()); }
inline iterator insert(T &&value)
@@ -244,7 +244,7 @@ Q_INLINE_TEMPLATE QSet<T> &QSet<T>::intersect(const QSet<T> &other)
copy2 = *this;
*this = copy1;
}
- for (const auto &e : qAsConst(copy1)) {
+ for (const auto &e : std::as_const(copy1)) {
if (!copy2.contains(e))
remove(e);
}
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 65c1c144f1..3fa9bbd0d8 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -443,6 +443,46 @@
*/
/*!
+ \fn template <class T> QSharedPointer<T>::QSharedPointer(QSharedPointer &&other)
+
+ Move-constructs a QSharedPointer instance, making it point at the same
+ object that \a other was pointing to.
+
+ \since 5.4
+*/
+
+/*!
+ \fn template <class T> QSharedPointer<T>::operator=(QSharedPointer &&other)
+
+ Move-assigns \a other to this QSharedPointer instance.
+
+ \since 5.0
+*/
+
+/*!
+ \fn template <class T> template <class X> QSharedPointer<T>::QSharedPointer(QSharedPointer<X> &&other)
+
+ Move-constructs a QSharedPointer instance, making it point at the same
+ object that \a other was pointing to.
+
+ This constructor participates in overload resolution only if \c{X*}
+ implicitly converts to \c{T*}.
+
+ \since 5.6
+*/
+
+/*!
+ \fn template <class T> template <class X> QSharedPointer<T>::operator=(QSharedPointer<X> &&other)
+
+ Move-assigns \a other to this QSharedPointer instance.
+
+ This assignment operator participates in overload resolution only if \c{X*}
+ implicitly converts to \c{T*}.
+
+ \since 5.6
+*/
+
+/*!
\fn template <class T> QSharedPointer<T>::QSharedPointer(const QWeakPointer<T> &other)
Creates a QSharedPointer by promoting the weak reference \a other
@@ -896,6 +936,15 @@
*/
/*!
+ \fn template <class T> qHash(const QSharedPointer<T> &key, size_t seed)
+ \relates QSharedPointer
+
+ Returns the hash value for \a key, using \a seed to seed the calculation.
+
+ \since 5.0
+*/
+
+/*!
\fn template <class T> template <class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
\relates QSharedPointer
diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h
index a18304cae6..2a60f3ca5e 100644
--- a/src/corelib/tools/qsharedpointer.h
+++ b/src/corelib/tools/qsharedpointer.h
@@ -48,6 +48,11 @@ public:
QSharedPointer<T> &operator=(QSharedPointer<T> &&other) noexcept;
QSharedPointer<T> &operator=(const QWeakPointer<T> &other);
+ template <class X>
+ QSharedPointer(QSharedPointer<X> && other) noexcept;
+ template <class X>
+ QSharedPointer &operator=(QSharedPointer<X> && other) noexcept;
+
void swap(QSharedPointer<T> &other) noexcept;
QWeakPointer<T> toWeakRef() const;
@@ -70,6 +75,9 @@ public:
};
template <class T>
+size_t qHash(const QSharedPointer<T> &key, size_t seed = 0) noexcept;
+
+template <class T>
class QWeakPointer
{
public:
diff --git a/src/corelib/tools/qtaggedpointer.h b/src/corelib/tools/qtaggedpointer.h
index 504645993a..a08912c4a5 100644
--- a/src/corelib/tools/qtaggedpointer.h
+++ b/src/corelib/tools/qtaggedpointer.h
@@ -72,11 +72,30 @@ public:
return !isNull();
}
- QTaggedPointer &operator=(T *other) noexcept
+#ifdef Q_QDOC
+ QTaggedPointer &operator=(T *other) noexcept;
+#else
+ // Disables the usage of `ptr = {}`, which would go through this operator
+ // (rather than using the implicitly-generated assignment operator).
+ // The operators have different semantics: the ones here leave the tag intact,
+ // the implicitly-generated one overwrites it.
+ template <typename U,
+ std::enable_if_t<std::is_convertible_v<U *, T *>, bool> = false>
+ QTaggedPointer &operator=(U *other) noexcept
+ {
+ T *otherT = other;
+ d = reinterpret_cast<quintptr>(otherT) | (d & tagMask());
+ return *this;
+ }
+
+ template <typename U,
+ std::enable_if_t<std::is_null_pointer_v<U>, bool> = false>
+ QTaggedPointer &operator=(U) noexcept
{
- d = reinterpret_cast<quintptr>(other) | (d & tagMask());
+ d = reinterpret_cast<quintptr>(static_cast<T *>(nullptr)) | (d & tagMask());
return *this;
}
+#endif
static constexpr Tag maximumTag() noexcept
{
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h
index 338f89d633..2058f6349e 100644
--- a/src/corelib/tools/qtools_p.h
+++ b/src/corelib/tools/qtools_p.h
@@ -54,6 +54,11 @@ constexpr inline char toAsciiLower(char ch) noexcept
return (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch;
}
+constexpr inline char toAsciiUpper(char ch) noexcept
+{
+ return (ch >= 'a' && ch <= 'z') ? ch - 'a' + 'A' : ch;
+}
+
constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept
{
const char lhsLower = QtMiscUtils::toAsciiLower(lhs);
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 54603bcec1..6ae3cc8308 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -172,6 +172,13 @@ public:
template <typename Predicate>
qsizetype removeIf(Predicate pred);
+ void clear()
+ {
+ if constexpr (QTypeInfo<T>::isComplex)
+ std::destroy_n(data(), size());
+ s = 0;
+ }
+
iterator erase(const_iterator begin, const_iterator end);
iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
@@ -180,11 +187,13 @@ public:
return qHashRange(begin(), end(), seed);
}
protected:
+ void growBy(qsizetype prealloc, void *array, qsizetype increment)
+ { reallocate_impl(prealloc, array, size(), (std::max)(size() * 2, size() + increment)); }
template <typename...Args>
reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args)
{
if (size() == capacity()) // ie. size() != 0
- reallocate_impl(prealloc, array, size(), size() << 1);
+ growBy(prealloc, array, 1);
reference r = *new (end()) T(std::forward<Args>(args)...);
++s;
return r;
@@ -206,9 +215,32 @@ protected:
}
void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n);
- void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc, const T *v = nullptr);
- void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T *v = nullptr)
- { reallocate_impl(prealloc, array, sz, qMax(sz, capacity()), v); }
+ void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc);
+ void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
+ {
+ if (QtPrivate::q_points_into_range(&v, begin(), end())) {
+ resize_impl(prealloc, array, sz, T(v));
+ return;
+ }
+ reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
+ while (size() < sz) {
+ new (data() + size()) T(v);
+ ++s;
+ }
+ }
+ void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
+ {
+ reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
+ if constexpr (QTypeInfo<T>::isComplex) {
+ // call default constructor for new objects (which can throw)
+ while (size() < sz) {
+ new (data() + size()) T;
+ ++s;
+ }
+ } else {
+ s = sz;
+ }
+ }
bool isValidIterator(const const_iterator &i) const
{
@@ -378,8 +410,11 @@ public:
template <typename U = T, if_copyable<U> = true>
#endif
void resize(qsizetype sz, const T &v)
- { Base::resize_impl(Prealloc, this->array, sz, &v); }
+ { Base::resize_impl(Prealloc, this->array, sz, v); }
+ using Base::clear;
+#ifdef Q_QDOC
inline void clear() { resize(0); }
+#endif
void squeeze() { reallocate(size(), size()); }
using Base::capacity;
@@ -695,7 +730,7 @@ Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *arr
const qsizetype asize = size() + increment;
if (asize >= capacity())
- reallocate_impl(prealloc, array, size(), qMax(size() * 2, asize));
+ growBy(prealloc, array, increment);
if constexpr (QTypeInfo<T>::isComplex)
std::uninitialized_copy_n(abuf, increment, end());
@@ -706,7 +741,7 @@ Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *arr
}
template <class T>
-Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc, const T *v)
+Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc)
{
Q_ASSERT(aalloc >= asize);
Q_ASSERT(data());
@@ -747,26 +782,6 @@ Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void
if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
free(oldPtr);
-
- if (v) {
- if constexpr (std::is_copy_constructible_v<T>) {
- while (size() < asize) {
- new (data() + size()) T(*v);
- ++s;
- }
- } else {
- Q_UNREACHABLE();
- }
- } else if constexpr (QTypeInfo<T>::isComplex) {
- // call default constructor for new objects (which can throw)
- while (size() < asize) {
- new (data() + size()) T;
- ++s;
- }
- } else {
- s = asize;
- }
-
}
template <class T>
@@ -834,29 +849,12 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *ar
Q_ASSERT(size() <= capacity());
Q_ASSERT(capacity() > 0);
- qsizetype offset = qsizetype(before - cbegin());
- if (size() == capacity())
- reallocate_impl(prealloc, array, size(), size() * 2);
- if constexpr (!QTypeInfo<T>::isRelocatable) {
- T *b = begin() + offset;
- T *i = end();
- T *j = i + 1;
- // The new end-element needs to be constructed, the rest must be move assigned
- if (i != b) {
- new (--j) T(std::move(*--i));
- while (i != b)
- *--j = std::move(*--i);
- *b = T(std::forward<Args>(args)...);
- } else {
- new (b) T(std::forward<Args>(args)...);
- }
- } else {
- T *b = begin() + offset;
- memmove(static_cast<void *>(b + 1), static_cast<const void *>(b), (size() - offset) * sizeof(T));
- new (b) T(std::forward<Args>(args)...);
- }
- this->s += 1;
- return data() + offset;
+ const qsizetype offset = qsizetype(before - cbegin());
+ emplace_back_impl(prealloc, array, std::forward<Args>(args)...);
+ const auto b = begin() + offset;
+ const auto e = end();
+ QtPrivate::q_rotate(b, e - 1, e);
+ return b;
}
template <class T>
@@ -864,28 +862,12 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *arr
{
Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
- qsizetype offset = qsizetype(before - cbegin());
- if (n != 0) {
- const T copy(t); // `t` could alias an element in [begin(), end()[
- resize_impl(prealloc, array, size() + n);
- if constexpr (!QTypeInfo<T>::isRelocatable) {
- T *b = begin() + offset;
- T *j = end();
- T *i = j - n;
- while (i != b)
- *--j = *--i;
- i = b + n;
- while (i != b)
- *--i = copy;
- } else {
- T *b = begin() + offset;
- T *i = b + n;
- memmove(static_cast<void *>(i), static_cast<const void *>(b), (size() - offset - n) * sizeof(T));
- while (i != b)
- new (--i) T(copy);
- }
- }
- return data() + offset;
+ const qsizetype offset = qsizetype(before - cbegin());
+ resize_impl(prealloc, array, size() + n, t);
+ const auto b = begin() + offset;
+ const auto e = end();
+ QtPrivate::q_rotate(b, e - n, e);
+ return b;
}
template <class T>
diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp
index 7d6ddc9bcd..f44d5e4e8c 100644
--- a/src/corelib/tools/qversionnumber.cpp
+++ b/src/corelib/tools/qversionnumber.cpp
@@ -404,19 +404,18 @@ static QVersionNumber from_string(QLatin1StringView string, qsizetype *suffixInd
QVarLengthArray<int, 32> seg;
const char *start = string.begin();
- const char *end = start;
const char *lastGoodEnd = start;
const char *endOfString = string.end();
do {
- bool ok = false;
- const qulonglong value = qstrntoull(start, endOfString - start, &end, 10, &ok);
- if (!ok || value > qulonglong(std::numeric_limits<int>::max()))
+ // parsing as unsigned so a minus sign is rejected
+ auto [value, end] = qstrntoull(start, endOfString - start, 10);
+ if (!end || value > qulonglong(std::numeric_limits<int>::max()))
break;
seg.append(int(value));
start = end + 1;
lastGoodEnd = end;
- } while (start < endOfString && end < endOfString && *end == '.');
+ } while (start < endOfString && *lastGoodEnd == '.');
if (suffixIndex)
*suffixIndex = lastGoodEnd - string.begin();