summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qsettings.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Bootstrap: remove QTemporaryFileThiago Macieira2024-03-131-2/+2
| | | | | | | | | Done by harmonizing the use on the QT_CONFIG(temporaryfile) macro and fixing one test that was missing. We can't remove the older macro because it is marked PBULIC) but we don't need to use it ourselves. Change-Id: I01ec3c774d9943adb903fffd17b7eb4dd1a4e63f Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* corelib: settings - make qsettings.cpp unity buildableTim Blechmann2024-02-261-0/+7
| | | | | | | | | | Both qsettings.cpp and qjsonparser.cpp defined Space in the global namespace. Hiding it in one of them in an implementation namespace resolves the name clash. Pick-to: 6.7 6.6 6.5 Change-Id: I8dd1244f80d87f3908597ed82c8e41b49b7b916c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Move the settingseditor example into tests/manualVolker Hilsheimer2023-12-151-5/+1
| | | | | | | | | | | | | | | | The example uses QTreeWidget when it should use a QTreeView with a dedicated item model, primarily shows how to use item views (and very little about QSettings), and is generally not useful to show how an application could or should use QSettings to store settings. Turn it into a manual test instead; it's useful for that as it supports ini and plist files, and settings in different scopes. Pick-to: 6.7 Fixes: QTBUG-119978 Change-Id: I7ce039f6391c41c679d126d90a251eee60327c39 Reviewed-by: Ed Cooke <ed.cooke@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Don't reuse iterator var to avoid -D_GLIBCXX_DEBUG crashMichael Weghorn2023-11-141-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For a CXXFLAGS='-D_GLIBCXX_DEBUG' build, running the examples/corelib/ipc/sharedmemory/sharedmemory example and clicking on the "Load Image from File..." button would result in a crash: > usr/include/c++/13/debug/safe_iterator.h:492: > In function: > bool gnu_debug::operator!=(const > _Safe_iterator<std::_Rb_tree_const_iterator<std::pair<const > QSettingsKey, QVariant> >, std::debug::map<QSettingsKey, QVariant, > std::less<QSettingsKey>, std::allocator<std::pair<const QSettingsKey, > QVariant> > >, std::forward_iterator_tag>::_Self&, const > _Safe_iterator<std::_Rb_tree_const_iterator<std::pair<const > QSettingsKey, QVariant> >, std::debug::map<QSettingsKey, QVariant, > std::less<QSettingsKey>, std::allocator<std::pair<const QSettingsKey, > QVariant> > >, std::forward_iterator_tag>::_Self&) > > Error: attempt to compare a singular iterator to a > singular (value-initialized) iterator. > > Objects involved in the operation: > iterator "lhs" @ 0x7ffe8e811550 { > type = std::_Rb_tree_const_iterator<std::pair<QSettingsKey const, QVariant> > (constant iterator); > state = singular; > } > iterator "rhs" @ 0x7ffe8e811670 { > type = std::_Rb_tree_const_iterator<std::pair<QSettingsKey const, QVariant> > (constant iterator); > state = singular (value-initialized); > } > Aborted (core dumped) This may be a libstdc++ bug, but still avoid/work around the issue by just using two separate variables for the iterators here. While at it, simplify the code a bit and replace the use of const_cast and pointers with the use of const references. Many thanks to Giuseppe D'Angelo for the analysis of the underlying problem and reporting a bug for GCC/libstdc++ [1] ! [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112477 Fixes: QTBUG-119044 Pick-to: 6.6 6.5 Change-Id: I00a8cc35033cf3ab4ba1f071cccabdef8ef52f9c Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Doc: Fix warnings and linking issuesTopi Reinio2023-10-091-3/+0
| | | | | | | | | | | | | | | | | | | | Remove or replace links to examples that were removed or moved under manual tests. Replace code snippets that were quoting the now-missing examples. Fix documentation of QSet::removeIf(). Fix typo in documentation macro: Unknown command '\examplecateogry'. Add qtopengl, qtshadertools dependencies to Qt Widgets documentation project to enable correct linking to those topics. Mark all documentation sets in qtbase as free of warnings. Pick-to: 6.6 6.5 Change-Id: I058cd5f2063aa933ea310bceff906f05422a7cb2 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* doc: Remove QSettings' paths for embedded linuxMohammadHossein Qanbari2023-09-071-6/+4
| | | | | | | | | | Embedded Linux is just Linux nowadays. Fixes: QTBUG-116715 Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I1f64d27550db6f711c7f1f578e85cad12d0973aa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Samuli Piippo <samuli.piippo@qt.io>
* Make IDB settings work sync with JSPIMikolaj Boc2023-08-211-0/+30
| | | | | | | | | | | | | | IndexedDB version of QSettings will now use solely the sync versions of data access functions. Those will suspend with JSPI. This makes IDB settings conform to the QSettings contract - and also allows us to enable tests in tst_qsettings for the IDB version of QSettings. Also, do not treat the IndexedDB format as one defining read/write functions in QSettings - those are the same as for ini format, as IndexedDB settings backend uses a backing ini file. Change-Id: Iee3471cc79c0cea87378923cf9baac58e56d1272 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Add WebLocalStorageFormat, WebIndexedIDBFormat to public APIMikolaj Boc2023-08-211-0/+10
| | | | | | Fixes: QTBUG-115587 Change-Id: Icb5dc795ad60608effbf08200592899d1a3d7fd1 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Call QConfFileSettingsPrivate::initAccess normally on WASMMikolaj Boc2023-07-281-2/+0
| | | | | | | | | | | | QConfFileSettingsPrivate::initAccess is not async, as the commit introducing compile guards around initAccess in ctor of QConfFileSettingsPrivate suggests. Calling initAccess is necessary to read stats from a conf file. This makes 50 more tests in tst_qsettings pass. Task-number: QTBUG-115509 Change-Id: I99e8970413a14d7b595be23d42bf46faa26b3dd7 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Remove references to Application ExampleAxel Spoerl2023-07-061-1/+1
| | | | | | | | | Removing dangling references to the example due to its move to manual tests. Pick-to: 6.6 6.5 Change-Id: I13f5fad93763d1ef70ddd8b3dcf430b5df8e28f9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Android: Restore the default QSettings path to the .config directoryBartlomiej Moskal2023-06-131-12/+28
| | | | | | | | | | | | | | After 140ca89a3c2b8d78889d27217f977cd4de10041b commit, the path of the QSettings default file location changed. That caused the problem with updating the app (old settings file is not used anymore). That is why we should still use old (.config) directory for QSettings file if the file exists. Pick-to: 6.2 6.5 6.6 Fixes: QTBUG-109405 Fixes: QTBUG-109369 Change-Id: I8ce53e0a80e4c2d16802b27b000ab3fbed198628 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definitionEdward Welbourne2023-03-201-6/+6
| | | | | | | | | | I got tired of being told off by the inanity 'bot for faithfully reflecting existing #if-ery in new #if-ery. Retain only the documentation and definition of the deprecated define. Change-Id: I47f47b76bd239a360f27ae5afe593dfad8746538 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Misc: Fix qsizetype-related narrowing coversionsAhmad Samir2023-03-111-1/+1
| | | | | | Task-number: QTBUG-102461 Change-Id: I96757abc50fc45756bc1271a970f819a48021663 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QtMiscUtils hex/oct-related helpersAhmad Samir2023-02-071-8/+6
| | | | | | | Thanks to Thiago for pointing them out in review. Change-Id: I14d588a8bd5ba29d43a5daeacfd55d974eb65557 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtMiscUtils: add some more character helpersAhmad Samir2023-02-071-8/+5
| | | | | | | | | | | | | isHexDigit, isOctalDigit, isAsciiDigit, isAsciiLower, isAsciiUpper, isAsciiLetterOrNumber. This de-duplicates some code through out. Rename two local lambdas that were called "isAsciiLetterOrNumber" to not conflict with the method in QtMiscUtils. Change-Id: I5b631f95b9f109136d19515f7e20b8e2fbca3d43 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QLatin1 QStringConverter methodsAhmad Samir2023-01-311-3/+1
| | | | | Change-Id: Ie28168250f3cd2a6ffe83f5ed783a1c21b754ee2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSettings: use QFileInfo::refresh()Ahmad Samir2022-12-231-3/+3
| | | | | | | | Not so much about performance as it is better readability, it's the same file, we're just rereading its metadata from the filesystem. Change-Id: Ia7ae35aea5fec67ead1fc8ead99586b3b0a14727 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QSettings: get file timestamps in UTC directlyAhmad Samir2022-12-231-4/+4
| | | | | | | | These are timestamps, so UTC is all we need. This is faster than getting the times in the Local Time Zone just to compare them. Change-Id: I5ceebafea12a7015dce9e3c00d1b35f8da2afb1d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-7/+7
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Simplify and tidy up various trivia in Q*SettingsPrivateEdward Welbourne2022-07-281-28/+18
| | | | | | | | | | | Eliminate needless linebreaks. Use ranged-for to simplify a loop. Use a startsWith() check for BOM and sliced() to take it into account. Use ternary in initializers rather than initializing a bool to then use in a ternary. Make explicit that some values are const. Use std::move() on a QVariant to save copying. Change-Id: Ie97da14906357803f8d5ada2e376b809f14bba54 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSettings: Fix reading of the [%General] sectionhjk2022-06-161-1/+1
| | | | | | | | | | The currentSection key was accidentally using the whole remaining section contents. Pick-to: 6.4 Change-Id: Iec6e38636e519170eef136401ede4b626e12754a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QSettings: fix a typo in the docLaszlo Papp2022-06-111-1/+1
| | | | | | Pick-to: 6.4 6.3 6.2 Change-Id: I059f603f3cc66a40e84179ac3f2a07de3bf31761 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Android: Fix QSettings when using content URLSamuel Mira2022-06-081-3/+18
| | | | | | | | | | | | | | | | | | | | | | | Using QSettings with Content URL in Android failed because of 3 issues: * the lock file assumed that it could append ".lock" to the file name for its name * the lock file assumed that it could write in the same directory as the file * the QSaveFile used by QSettings requires direct write on content URL but setDirectWriteFallback is set to false on QSettings by default This patch fixes those issues by, when it is an Content URL in Android, saving the lock file in QStandardPaths::CacheLocation and setting the setDirectWriteFallback to true. This does not break backwards compatibility because appending ".lock" to the Content URL will always make an invalid URL, so it did not work before. Fixes: QTBUG-103455 Pick-to: 6.3 6.2 Change-Id: I92867577507b7069e4e6091d94e0931bb6dbcbed Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtCore: remove the remaining uses of QLatin1StringSona Kurazyan2022-04-261-1/+1
| | | | | | Task-number: QTBUG-98434 Change-Id: Iba9194f525d983f735d3927a0dbfae6b9013c408 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Simplify QConfFileSettingsPrivate::readIniSection() using QBAVEdward Welbourne2022-04-261-16/+15
| | | | | | | | | It needs fewer moving parts this way. In the process, to match the QString strValue, rename a QString key to strKey, freeing the name key for a view. Change-Id: Ic58145fd665db265d136545ced59e293a2eed1eb Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Correct documentation of INI format's loss of type informationEdward Welbourne2022-04-261-5/+8
| | | | | | | | | | | | Although it loses type information for numeric types, it does preserve the type of most other values. This amends commit ee8a5f4917d98a26f8dedd6802eac754d748b227 Pick-to: 6.3 6.2 5.15 Change-Id: Id4d0e11eabff1874869b940c05055e0bebef5963 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Tidy up some local variables in QSettingsPrivate::iniEscapedString()Edward Welbourne2022-04-211-4/+3
| | | | | | | | | | | A loop variable could just as well be declared in the loop. The startPos variable sits more naturally just before its first use than where the removal of the loop variable's declaration left it isolated. Change-Id: I4754b9dfe4b142e5a183a0d9555c9d3237bc6bbd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix handling of DateTime values in QSettingsEdward Welbourne2022-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since 5.6.0, Qt's serialization of QDateTime in QSettings files has had special-case handling to use a newer QDataStream version than the one QSettings uses for most other types. This was handled in the serialization and parsing, but not taken into account in the code that turned binary data into content suitable for saving to an ini file. In Qt 5 this caused no problem when no iniCodec was set on the QSettings object but Qt 6 now uses UTF-8 as (in effect) codec on every QSettings object. This lead to the binary data encoding QDateTime being encoded as if it were Unicode, instead of using \x tokens where suitable. This lead to an unintended incompatible change in how QSettings stores QDateTime values: Qt 6 was still able to read Qt 5's values, but Qt 5 was unable to read Qt 6's settings files (unless it sets its iniCodec to UTF-8, which works round the problem). The code to convert raw binary data to ini-file-friendly value texts had a special case for ByteArray and Variant values, to ignore the codec and use \x tokens: when support for QDateTime was split from Variant, it gained a DateTime prefix in the parsing code that wasn't included in this special handling. So add that now. The resulting DateTime values now match Qt 5 so are readable by it and by Qt 6 (including versions prior to this change); and the code to read a DateTime can still read what earlier Qt 6 versions have been writing. It is likely a Qt 5 QSettings with an iniCodec other than UTF-8 may have problems with the result, but that was already true. This amends commit 73b8cd879cd723fbcce42e63f21cc864d13cb91e Fixes: QTBUG-102334 Pick-to: 6.2 6.3 5.15 Change-Id: Icc44a33db3dcc6400144bc001710b400ee883c90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* QSettings: fix a misleading commentMarc Mutz2022-04-061-1/+2
| | | | | | | | | | | | | | | | Destructors in C++ are implicitly noexcept, so the try-catch around QSettingsPrivate::flush() is not to prevent throwing from a dtor (anymore), but to prevent a throw statement inside flush() from taking down the whole application. We don't need to care about abi::__forced_unwind here, since we couldn't re-throw it even if we wanted to (throw in noexcept function is direct std::terminate(); at least by not re-throwing, the user will get a nice complaint message from the runtime). Pick-to: 6.3 Change-Id: I3b24a4be9aeb74637a58725540990b535d005bdd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify parsing of a line to remove [...] enclosureEdward Welbourne2022-04-011-11/+9
| | | | | | | | | Use a view of the line, within the larger data buffer, to avoid some complications. Change-Id: Iaf79068487ac6b92fe9e415fb63f6b0e9ad0c5a2 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSettings: use auto rather than naming iterator typesEdward Welbourne2022-03-301-19/+15
| | | | | | | Not always possible, but avoid the noise where we can. Change-Id: I4a37cc3e806b1b9d696647aca7303b30e36b471b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSettings: s/int/qsizetype/ on the internalsEdward Welbourne2022-03-301-50/+51
| | | | | | | | | | | Can't change the public API, but we can at least change the internals to use the right type, ready for when we do. Also changed some C-style casts to function-style, even when the type remains int; renamed an inner loop variable to avoid shadowing an outer; and changed a use of count() to size(). Change-Id: Id52ce0a2f0177bf1d6dfbd45a592a45afcddf9b4 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSettingsPrivate: fold from/to parameters into the view they boundEdward Welbourne2022-03-301-16/+18
| | | | | | | | | | Two methods of the private class used to take a QByteArray with from and to indices into it, for where to start and stop a scan. Now that they take a QByteArrayView, those parameters can be used by the caller to shorten the view to the desired portion. Change-Id: Id1586afb87a9e8a189b69e485278375ff504fb7b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Use QByteArrayView more in QConfFileSettingsPrivate's methodsEdward Welbourne2022-03-301-10/+10
| | | | | | | | | | Avoid allocating QBA methods when the QBAV methods can do just as well, especially where the QBA was already being QBAV-wrapped to avoid such allocations. Change-Id: I180c2316362685ffda613bab2c761e72c4483fce Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Prefer sliced()/first()/chopped() to mid() and arithmeticEdward Welbourne2022-03-301-8/+8
| | | | | | | | The newer methods bypass checking and make it clearer what's happening. They're also available on QBAV, unlike mid(). Change-Id: Ie0375888b889e393b91814ba80529d1a7227eb7f Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Apply Q_CONSTINIT across the codebaseMarc Mutz2022-03-291-1/+1
| | | | | | | | | Still not complete. Just grepping for static and thread_local. Task-number: QTBUG-100486 Change-Id: I90ca14e8db3a95590ecde5f89924cf6fcc9755a3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Short live Q_CONSTINIT!Marc Mutz2022-03-261-1/+1
| | | | | | | | | | | | | | | | | | It expands to the first available of - constinit (C++20) - [[clang::require_constant_initialization]] (Clang) - __constinit (GCC >= 10) Use it around the code (on and near static QBasicAtomic; this patch makes no attempt to find all statics in qtbase). [ChangeLog][QtCore][QtGlobal] Added macro Q_CONSTINIT. Fixes: QTBUG-100484 Change-Id: I11e0363a7acb3464476859d12ec7f94319d82be7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-4/+4
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QSettings: fix formatting to match our coding styleSona Kurazyan2022-03-261-7/+5
| | | | | Change-Id: I5cde2498e6423284f8abec7e717f262b6ea9eed8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-52/+54
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* QSettings: port API from QString to QAnyStringView keysMarc Mutz2022-03-231-10/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the public interface ported to QAnyStringView, we can now internally optimize memory allocations _in a central place_ (e.g. by returning std::u16string or QVarLengthArray<QChar> from normalizeKey() instead of QString). But first we needed to get rid of all the unwarranted allocations in user code. Effects on Linux AMD64 stripped C++20 release builds: GCC 11.2 libstdc++ (TEXT -= 6.5%): text data bss dec hex filename 635148 10992 2824 648964 9e704 tst_qsettings-01-baseline 593691 10992 2824 607507 94513 tst_qsettings-02-qanystringview Clang 10.0.0 libc++ (TEXT -= 11.6%(!)): text data bss dec hex filename 790336 10640 2832 803808 c43e0 tst_qsettings-01-baseline 698572 10640 2832 712044 add6c tst_qsettings-02-qanystringview That's the beauty of QAnyStringView: transparently reducing temporary QString creation; and the simplest code is also the most efficient. [ChangeLog][QtCore][QSettings] Keys can now be passed as QAnyStringView (was: QString). The most efficient way to pass literal keys is now "key"_L1, the backwards-compatible way is QStringLiteral("key"). Fixes: QTBUG-101390 Change-Id: I510fb4ce17ef109dac7c9cdc5d90ede0d1a9db5f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QSettings: port key processing to QAnyStringViewMarc Mutz2022-03-191-25/+55
| | | | | | | | | | | | | | | | | | | | | | | ... in preparation for replacing the QString keys in the public API with QAnyStringView ones. This removes the "important optimization" that avoids a detach in the common case where the input is the same as the output of normalization. But that optimization is beside the point, because it trades a memory allocation avoided in the library for O(N) allocations inserted into user code for each call to QSettings::value(), the vast majority of which are calls with string literals. With the public interface ported to QAnyStringView in the follow-up patch, we can then internally optimize memory allocations _in a central place_ (e.g. by returning std::u16string or QVarLengthArray<QChar> from normalizeKey() instead of QString). But first we need to get rid of all the unwarranted allocations in user code. Change-Id: I45fc83d972c552a220c9c29508001d3f172e1162 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSettings: support reading UTF-8 keys in INI filesIvan Solovev2022-03-021-14/+18
| | | | | | | | | | | | | | [ChangeLog][QtCore][QSettings] The INI file reader now supports keys encoded with UTF-8, as well as the %-encoded format. Writing the keys back to the INI file is still done using %-encoded format. This change does not touch the way the *values* are handled - they are both read and written in UTF-8. Drive-by: remove misleading comments from the reading algorithm. Task-number: QTBUG-99401 Change-Id: I6a83cbf24d919a499540403688615f93cb195e93 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QSettings: overload value() instead of using a default argumentMarc Mutz2022-02-201-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | ... of non-trivial type, which needs to be constructed every time the function is called, no matter whether the user supplies one or not. Effects on Linux AMD64 O2 C++20 tst_qsettings builds, as an example heavy-duty QSettings::value() user: GCC 11.2 libstdc++ (TEXT -= 4.6%): text data bss dec hex filename 662317 10952 2824 676093 a50fd tst_qsettings-00-baseline 631849 10960 2824 645633 9da01 tst_qsettings-01-qvariant Clang 10.0.0 libc++ (TEXT -= 2.8%) text data bss dec hex filename 808448 10616 2832 821896 c8a88 tst_qsettings-00-baseline 785890 10624 2832 799346 c3272 tst_qsettings-01-qvariant Pick-to: 6.3 Task-number: QTBUG-98117 Change-Id: I7366f063e3ec34c040fd35ffd274e8ed5a722132 Reviewed-by: Kai Koehne <kai.koehne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QSettings: use QtMiscUtils hex tools instead of rolling your ownMarc Mutz2022-02-091-6/+5
| | | | | | | | | Removes a static string literal. QtMiscUtils allows the compiler to possibly avoid the array, or share with other TUs Pick-to: 6.3 Change-Id: I449800f113620a53d2f4b11fe027ebcb710f7b86 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* corelib: Fix typos in source code commentsJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 6.2 Change-Id: Ic78afb67143112468c6f84677ac88f27a74b53aa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Port QSettingsPrivate::get() to std::optionalMarc Mutz2021-06-301-10/+5
| | | | | | | | ... instead of a bool return and a QVariant out parameter. Change-Id: I9d937668ede668075d1de5bb57f61e4c260aaddc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>