Skip to content

Commit

Permalink
Update for Qt-6.6
Browse files Browse the repository at this point in the history
Qt-6.6 deprecates qAsConst in favour of std::as_const() but the latter
is only available as of C++17. Therefore define a local helper template
instead.
  • Loading branch information
leonlynch committed Dec 10, 2023
1 parent bb75808 commit 980bbac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ cmake --build build --target package
Qt
--

This project supports Qt 5.12.x, Qt 5.15.x and Qt 6.5.x (although it may be
possible to use other versions of Qt) when building the `dukpt-ui` application.
However, on some platforms it may be necessary to use the `QT_DIR` option (and
not the `Qt5_DIR` nor `Qt6_DIR` options) or `CMAKE_PREFIX_PATH` option to
specify the exact Qt installation to be used. For Qt6 it may also be necessary
for the Qt tools to be available in the executable PATH regardless of the
`QT_DIR` option.
This project supports Qt 5.12.x, Qt 5.15.x, Qt 6.5.x and Qt 6.6.x (although it
may be possible to use other versions of Qt) when building the `dukpt-ui`
application. However, on some platforms it may be necessary to use the `QT_DIR`
option (and not the `Qt5_DIR` nor `Qt6_DIR` options) or `CMAKE_PREFIX_PATH`
option to specify the exact Qt installation to be used. For Qt6 it may also be
necessary for the Qt tools to be available in the executable PATH regardless of
the `QT_DIR` option.

If the Qt installation does not provide universal binaries for MacOS, it will
not be possible to build `dukpt-ui` as a universal binary for MacOS.
Expand Down
15 changes: 13 additions & 2 deletions ui/validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@

#include <cctype>

// QString performs a deep copy when begin() is called by a ranged-based for
// loop, but std::as_const() is only available as of C++17 and qAsConst is
// deprecated by Qt-6.6. Therefore define a local helper template instead.
template<class T>
constexpr std::add_const_t<T>& to_const_ref(T& t) noexcept
{
return t;
}
template<class T>
void to_const_ref(const T&&) = delete;

void DecStringValidator::setMinLength(unsigned int x)
{
if (x != minLength) {
Expand Down Expand Up @@ -62,7 +73,7 @@ QValidator::State DecStringValidator::validate(QString& input, int& pos) const
}

// Ensure that decimal string contains only decimal digits
for (QChar c : qAsConst(input)) {
for (QChar c : to_const_ref(input)) {
if (!std::isdigit(c.toLatin1())) {
// Non-decimal digit is not allowed
return Intermediate;
Expand All @@ -80,7 +91,7 @@ QValidator::State HexStringValidator::validate(QString& input, int& pos) const
}

// Ensure that hex string contains only hex digits
for (QChar c : qAsConst(input)) {
for (QChar c : to_const_ref(input)) {
if (!std::isxdigit(c.toLatin1())) {
// Non-hex digit is not allowed
return Intermediate;
Expand Down

0 comments on commit 980bbac

Please sign in to comment.