Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all Qt 5.15 deprecation warnings #7783

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

c4rlo
Copy link
Contributor

@c4rlo c4rlo commented Apr 3, 2022

Fix all deprecation warnings when building against Qt 5.15. This is a first step towards being able to eventually upgrade to Qt 6 (see #7774 for discussion).

This now builds cleanly with -DWITH_XC_ALL=ON -DWITH_GUI_TESTS=ON -DWITH_DEV_BUILD=ON.

Since this is a sizeable change, I've done my best to structure this sensibly into a set of commits.

I've assumed here that the earliest Qt version we support is 5.9.5, as stated in INSTALL.md. I have adjusted the check in CMakeLists.txt accordingly (0a1e776). In some cases I've resorted to compile-time checks for the Qt version.

One particular annoyance is that QUrl::topLevelDomain() has been deprecated without direct replacement. I worked around that by accessing its functionality indirectly (9ed6095).

Testing strategy

Built with -DWITH_XC_ALL=ON -DWITH_GUI_TESTS=ON -DWITH_DEV_BUILD=ON -DCMAKE_BUILD_TYPE=Debug and ran all tests.

Did the same thing in an Ubuntu 18.04 container that has libbotan-kpxc-2-dev from ppa:phoerious/keepassxc installed in it. This one did cause some test failures (in TestCli::testClip() and TestCli::testInvalidDbFiles()), but those also failed against the 2.7.4 tag, so I feel okay about them.

Suggestion

In order to keep the code base deprecation-clean, it would be excellent if the automated tests (i.e. TeamCity) could be enhanced to build with -DWITH_XC_ALL=ON -DWITH_GUI_TESTS=ON -DWITH_DEV_BUILD=ON -DCMAKE_BUILD_TYPE=Debug and ideally against different Qt versions, including Qt 5.9.5 (assuming that we want to keep supporting it) and Qt 5.15 (the last Qt 5 version).

Type of change

  • ✅ Refactor (significant modification to existing code)

@c4rlo c4rlo changed the title Fix all Qt 5.15 deprecation warnings [WIP] Fix all Qt 5.15 deprecation warnings Apr 3, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2022

Codecov Report

Attention: Patch coverage is 70.54545% with 81 lines in your changes are missing coverage. Please review.

Project coverage is 64.85%. Comparing base (c81e4e1) to head (0914ce9).

Current head 0914ce9 differs from pull request most recent head db4eb2d

Please upload reports for the commit db4eb2d to get more accurate results.

Files Patch % Lines
src/cli/DatabaseEdit.cpp 46.15% 7 Missing ⚠️
src/gui/entry/EntryModel.cpp 12.50% 7 Missing ⚠️
src/cli/Analyze.cpp 33.33% 6 Missing ⚠️
src/cli/Utils.cpp 62.50% 6 Missing ⚠️
src/gui/styles/base/BaseStyle.cpp 0.00% 6 Missing ⚠️
src/browser/BrowserEntryConfig.cpp 0.00% 4 Missing ⚠️
src/cli/Edit.cpp 33.33% 4 Missing ⚠️
src/core/PasswordHealth.cpp 0.00% 4 Missing ⚠️
src/cli/Add.cpp 40.00% 3 Missing ⚠️
src/cli/DatabaseCreate.cpp 72.73% 3 Missing ⚠️
... and 23 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7783      +/-   ##
===========================================
+ Coverage    63.65%   64.85%   +1.20%     
===========================================
  Files          360      342      -18     
  Lines        44254    44416     +162     
===========================================
+ Hits         28169    28804     +635     
+ Misses       16085    15612     -473     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tenzap
Copy link
Contributor

tenzap commented Apr 4, 2022

FYI, with 2.7.0 (+ c33995e) it is still possible to build with Qt 5.5 (but not below)

@c4rlo
Copy link
Contributor Author

c4rlo commented Apr 4, 2022

FYI, with 2.7.0 (+ c33995e) it is still possible to build with Qt 5.5 (but not below)

Hmm, so what is the minimum Qt version the maintainers want to support? Currently, 5.9.5 is what's documented (in INSTALL.md).

@c4rlo c4rlo force-pushed the qt-modernize branch 6 times, most recently from e40c912 to 7e867bf Compare April 18, 2022 12:54
@c4rlo c4rlo changed the title [WIP] Fix all Qt 5.15 deprecation warnings Fix all Qt 5.15 deprecation warnings Apr 18, 2022
@c4rlo
Copy link
Contributor Author

c4rlo commented Apr 18, 2022

Ok, I think this is in a reasonable state now. Regarding the test failures:

Ubuntu failure

From the logs, this is:

[12:58:26]
[Step 3/3] FAIL!  : TestKdbx4Format::testCustomData() Compared values are not the same
[12:58:26]
[Step 3/3]    Loc: [/opt/buildagent/work/c401303cba1b4098/tests/TestKdbx4.cpp(471)]

That line is:

    QCOMPARE(*clonedEntry->customData(), *entry->customData());

Now, Entry::clone() calls CustomData::copyDataFrom(), which calls CustomData::updateLastModified(), which can modify the custom data if we're just on the cusp of a new second; so I suspect that might be a pre-existing bug (likely affecting only the tests) that happens occasionally.

Windows failure

Not much detail in the logs, just:

[13:01:48]
[Step 3/4] 1/3 Test #39: testgui ..........................***Failed   23.33 sec

Since I don't have a Windows build setup ready to go, I'd appreciate any hints or details.

@droidmonkey
Copy link
Member

You can ignore the gui failures, they are transient

@c4rlo
Copy link
Contributor Author

c4rlo commented Apr 18, 2022

Cool. My latest update just rebased against develop; good to see that both failures have gone away. From my POV, this now seems good to merge.

The CustomData failure is as I suspected, I'll open a separate PR for that.

c4rlo added a commit to c4rlo/keepassxc that referenced this pull request Apr 18, 2022
Otherwise, assertions in TestKdbx4::testCustomData() may fail on rare
occasions, because the customData in a cloned entry won't be identical
to its original, because of its potentially-updated LastModified
property.

Originally noticed in
keepassxreboot#7783 (comment).
droidmonkey pushed a commit that referenced this pull request Apr 18, 2022
Otherwise, assertions in TestKdbx4::testCustomData() may fail on rare
occasions, because the customData in a cloned entry won't be identical
to its original, because of its potentially-updated LastModified
property.

Originally noticed in
#7783 (comment).
t-h-e pushed a commit to t-h-e/keepassxc that referenced this pull request Sep 8, 2022
Otherwise, assertions in TestKdbx4::testCustomData() may fail on rare
occasions, because the customData in a cloned entry won't be identical
to its original, because of its potentially-updated LastModified
property.

Originally noticed in
keepassxreboot#7783 (comment).
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/cli/Utils.h Outdated Show resolved Hide resolved
src/core/Global.h Outdated Show resolved Hide resolved
src/core/Tools.cpp Outdated Show resolved Hide resolved
src/core/Tools.cpp Outdated Show resolved Hide resolved
@c4rlo
Copy link
Contributor Author

c4rlo commented May 27, 2024

Okay, great. I have resolved all merge conflicts and rebased this PR against develop. As part of that, I removed the commit that fixed how top-level domains are resolved, since #9935 has now taken care of that. I have also added a couple extra commits that address some Botan deprecations. Edit: A couple of Botan deprecations are addressed separately in #10826; when that PR is combined with this one, a -DWITH_DEV_BUILD=ON build compiles successfully.

I have re-run the tests as stated in the original PR descriptions. Everything still works, except that when using an Ubuntu 18.04 container, there's now a few more CLI and GUI related test failures, but not sure how relevant those are [1]. Hopefully the GitHub checks that get run as part of this PR will show more relevant results.

[1] Edit: I've compared these failures against the develop branch, and they all happen there too, so definitely nothing to worry about. For completeness, here they are:

FAIL!  : TestCli::testClip() '!errorOutput.contains("All clipping programs failed")' returned FALSE. ()
   Loc: [/keepassxc-src/tests/TestCli.cpp(653)]

FAIL!  : TestCli::testInvalidDbFiles() Compared values are not the same
   Actual   (QString(m_stderr->readAll()))                                                 : "Enter password to unlock /tmp/testcli.K17361: \nError while reading the database: Failed to read database file.\n"
   Expected (QObject::tr("Failed to open database file %1: not readable").arg(path) + "\n"): "Failed to open database file /tmp/testcli.K17361: not readable\n"
   Loc: [/keepassxc-src/tests/TestCli.cpp(2225)]

Again, this is in an Ubuntu 18.04 container; they don't occur on my Arch Linux machine. They look like artefacts of running the tests in a container, where some stuff doesn't work correctly.

src/keys/drivers/YubiKey.h Outdated Show resolved Hide resolved
@droidmonkey
Copy link
Member

I'll merge this after 2.7.9 is bottled up, don't need any merge conflicts between branches.

c4rlo added a commit to c4rlo/keepassxc that referenced this pull request Jun 2, 2024
It does not need to be a recursive mutex, as per
keepassxreboot#7783 (comment).
c4rlo added 19 commits June 2, 2024 14:11
This is in agreement with our stated requirements in INSTALL.md.
qSort() is deprecated.
QDateTime::toString(Qt::DefaultLocaleShortDate) will go away in Qt 6;
replace it as recommended in the docs, introducing a Clock::toString()
helper function.

The replacement functionality we use already exists in Qt 5.9.5, our
minimum supported Qt version.
Replace it with

  QLocale::system().toString(..., QLocale::ShortFormat)

as recommended in the official docs.

The replacement already exists in Qt 5.9.5, our earliest supported Qt
version.
...instead of QDate(QDateTime) constructor, which is deprecated as of Qt
5.15.

Since QDateTime::startOfDay() is only available in Qt 5.14, we need to
use an #if.
QString::SplitBehavior (of which SkipEmptyParts is an element) was
deprecated in Qt 5.15.

Its designated replacement, Qt::SplitBehavior, was only added in Qt
5.14. Hence we need to use some preprocessor magic to keep supporting
older Qt versions (we require at minimum Qt 5.9.5).
It is deprecated as of Qt 5.15.
QSet::toList() is deprecated as of Qt 5.14.

Use the recommended replacement QSet::values() instead. It already
exists as of Qt 5.9.5, our minimum supported Qt version.
Both methods are deprecated since Qt 5.14.

The recommended replacement

  QSet(list.begin(), list.end())

is only available from Qt 5.14. Since we support Qt 5.9.5 or better,
provide our own 'Tools::asSet()' helper function for this purpose.
QHash::insertMulti is deprecated as of Qt 5.15.

QMultiHash already exists in Qt 5.9.5, our earliest supported Qt
version.
The overload we were using before has been deprecated in Qt 5.15. To get
the same behaviour as before, we need to use QProcess::splitCommand(),
which was only introduced in Qt 5.15, hence we need to use an #if for
the Qt version.
QProcess::pid() has been deprecated since Qt 5.15. Recommended
replacement QProcess::processId() exists since Qt 5.3.
The "HighQuality" version is deprecated as of Qt 5.14.

Since it's not immediately clear at which point in Qt version history it
becomes preferable to use the non-"HighQuality" one, we only do so in Qt
5.14 onwards.
QPalette::background() is deprecated as of Qt 5.13.

Its replacement, QtPalette::window(), is already available in Qt 5.9.5,
our minimum supported Qt version.
Instead of their deprecated aliases.
Qt 5.15 deprecates usage of non-'Qt::'-prefixed 'endl' and 'flush' I/O
manipulators.

Since the 'Qt::' versions are only introduced in Qt 5.14, we backport
them for older Qt versions (since we support down to Qt 5.9.5).
Instead of deprecated constructor QMutex(QMutex::RecursionMode), use
recommended replacement class QRecursiveMutex.

This deprecation was done only in the KDE branch of Qt, specifically in
https://invent.kde.org/qt/qt/qtbase/-/commit/6d5988831862f081404270bd7fa2f25bc836fdc9.
Since that commit is included in the Qt packaged for some Linux
distributions (e.g. Arch Linux:
https://archlinux.org/packages/extra/x86_64/qt5-base/), it seems worth
respecting this deprecation.

Since QRecursiveMutex was only introduced in Qt 5.14, whereas we need to
support Qt 5.9.5 or better, this involves some #ifdef magic.
Use non-deprecated QComboBox::sizeAdjustPolicy setting
It does not need to be a recursive mutex, as per
keepassxreboot#7783 (comment).
@c4rlo
Copy link
Contributor Author

c4rlo commented Jun 2, 2024

I'll merge this after 2.7.9 is bottled up, don't need any merge conflicts between branches.

I've just rebased this again so there shouldn't be any merge conflicts (but don't mind if you want to defer merge after 2.7.9 anyway).

@c4rlo c4rlo mentioned this pull request Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants