qt: Fix deprecated warning on newer Qt5 & always localize date format
Summary
When building with Qt5 5.15.2, I am consistently getting this deprecated
warning in bantablemnodel.cpp
:
[31/56] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bantablemodel.cpp.o
../src/qt/bantablemodel.cpp:120:42: warning: 'SystemLocaleLongDate' is deprecated: Use QLocale [-Wdeprecated-declarations]
return date.toString(Qt::SystemLocaleLongDate);
^
/Users/calin/Qt512/5.15.2/clang_64/lib/QtCore.framework/Headers/qnamespace.h:1283:30: note: 'SystemLocaleLongDate' has been explicitly marked deprecated here
SystemLocaleLongDate Q_DECL_ENUMERATOR_DEPRECATED_X("Use QLocale"),
This led me to investigate the formatting of QDateTime -> QString in the Qt app and I realized none of the date formatting is localized (it always uses "system" locale which may not match the app settings!).
This commit fixes the situation, by making all of the date formatting in
the app go through central GUIUtil::dateTimeStr*
functions.
- All calls to the deprecated
QDateTime::fromTime_t
have been replaced with the Qt 5.8+ functionQDateTime::fromSecsSinceEpoch
. - The existing
dateTimeStr
was updated to no longer use the deprecatedfromTime_t
API - Existing calls to QDateTime::toString() were replaced with calls to
GUIUtil::dateTimeStr()
orGUIUtil::dateTimeStrLong()
, etc, depending on the situation
These fixes localize the date/time displayed in:
- Short form in e.g. the transaction history (they are now properly localized)
- Long form for e.g. the ban table and the Node Window "information" tab.
Test Plan
ninja all check
- Load up the BitcointQt wallet, ban a peer, check that the ban table display is correct.
- Load up the UI again using a different language e.g.
-lang=de_DE
or-lang=ro_RO
and check that the date format reflects the language setting. - Do the above also for the transaction history dates (short dates) and for the Node Window -> Information tab. All datetimes should be localized.
To view the bug before this commit:
- Try the above using an alternate language against
master
and note how the locale setting is not reflected in the date format in the UI. - Also note how when it builds, it may produce deprecated warnings if you are using Qt 5.15.x
Before:
After:
Note
It was not possible to get Qt to use QLocale
to generate the exact same format string using the "default" locale as we had before. Qt has a sort of messy date/time formatting API. It is my opinion that the slightly longer string generated now is an improvement, since it also contains better timezone information, and it is more human readable in my opinion.