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

Warnings due to Qt 6.8.0 deprecating the constructor of QDateTime taking Qt::TimeSpec #207

Open
bobhairgrove opened this issue Oct 10, 2024 · 1 comment

Comments

@bobhairgrove
Copy link

bobhairgrove commented Oct 10, 2024

There needs to be a minor change in the two files quazip_qt_compat.h and quazipfileinfo.cpp when compiling with Qt 6.8.0 or later. Everything before that version compiles without any warnings (on GCC, but I disabled warnings when compiling with MSVC). (EDIT: using Qt 5.15.5 still compiles OK with the new #if ... #else guards in place).

The warning given when compiling the code with Qt 6.8.0 (using GCC 11.4.0 on Linux Ubuntu 22.04) is:

In file included from ../../../3rd_party/quazip/quazip.h:30,
                 from ../../../3rd_party/quazip/JlCompress.h:29,
                 from ../../../3rd_party/quazip/JlCompress.cpp:26:
../../../3rd_party/quazip/quazip_qt_compat.h: 
../../../3rd_party/quazip/quazip_qt_compat.h:110:59: 
In function ‘quint64 quazip_ntfs_ticks(const QDateTime&, int)’:
warning: ‘QDateTime::QDateTime(QDate, QTime, Qt::TimeSpec, int)’ is deprecated: 
Pass QTimeZone instead [-Wdeprecated-declarations]
  110 |     QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);

I tested using an #include guard:

// At line 106:
// this is not a deprecation but an improvement, for a change
#include <QtCore/QDateTime>
#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
    QDateTime base(QDate(1601, 1, 1), QTime(0, 0), QTimeZone(Qt::UTC));
    return base.msecsTo(time) * 10000 + fineTicks;
}
#elif (QT_VERSION >= 0x040700)
// etc.

Also, in the file quazipfileinfo.cpp: #include at the top:

#include <QtCore/QDataStream>
#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
#include <QTimeZone>
#endif

Then at line 129:

#if QT_VERSION >= QT_VERSION_CHECK(6,8,0)
    QDateTime base(QDate(1601, 1, 1), QTime(0, 0), QTimeZone(Qt::UTC));
#else
    QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
#endif
    dateTime = base.addMSecs(time / 10000);
// etc.
@bobhairgrove
Copy link
Author

Since I am building QuaZip by including the source files in my application, I have no way of testing whether or not the proposed changes have implications for the build toolchain. That is why I have not forked the project and made a pull request, but rather just show the changes here. But the changes are very small, so I think it should be OK.

cen1 pushed a commit that referenced this issue Oct 24, 2024
Since Qt 6.8 constructor of QDateTime, which accepts TimeSpec enum,
is marked as deprecated. To compile at this version without warnings it is necessary to
explicitly pass QTimeZone instead.

To save work with lower version of Qt, version check macro was added.

issue: #207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant