Skip to content

Commit 2a76f2e

Browse files
authored
Merge pull request #42 from Lord-Grey/Support_Qt6.7.0
Support Qt 6.7.0 - Address that qAsConst has been deprecated
2 parents 0ca8011 + a592b0b commit 2a76f2e

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ endif()
4444

4545
add_library(qmdnsengine ${HEADERS} ${SRC})
4646

47+
if ( "${QT_VERSION}" VERSION_GREATER_EQUAL "6.7.0" )
48+
message( STATUS "QMdnsEngine: Enable C++17 for Qt 6.7 and newer" )
49+
set_target_properties(qmdnsengine PROPERTIES
50+
CXX_STANDARD 17
51+
)
52+
else()
53+
set_target_properties(qmdnsengine PROPERTIES
54+
CXX_STANDARD 11
55+
)
56+
endif()
57+
4758
set_target_properties(qmdnsengine PROPERTIES
48-
CXX_STANDARD 11
4959
CXX_STANDARD_REQUIRED ON
5060
DEFINE_SYMBOL QT_NO_SIGNALS_SLOTS_KEYWORDS
5161
DEFINE_SYMBOL QT_NO_FOREACH

src/src/browser.cpp

+32-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* IN THE SOFTWARE.
2323
*/
2424

25+
#include <utility>
26+
2527
#include <qmdnsengine/abstractserver.h>
2628
#include <qmdnsengine/browser.h>
2729
#include <qmdnsengine/cache.h>
@@ -89,7 +91,11 @@ bool BrowserPrivate::updateService(const QByteArray &fqName)
8991
QList<Record> txtRecords;
9092
if (cache->lookupRecords(fqName, TXT, txtRecords)) {
9193
QMap<QByteArray, QByteArray> attributes;
92-
for (const Record &record : qAsConst(txtRecords)) {
94+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
95+
for (const Record &record : std::as_const(txtRecords)) {
96+
#else
97+
for (const Record &record : qAsConst(txtRecords)) {
98+
#endif
9399
for (auto i = record.attributes().constBegin();
94100
i != record.attributes().constEnd(); ++i) {
95101
attributes.insert(i.key(), i.value());
@@ -154,7 +160,11 @@ void BrowserPrivate::onMessageReceived(const Message &message)
154160
// For each of the services marked to be updated, perform the update and
155161
// make a list of all missing SRV records
156162
QSet<QByteArray> queryNames;
157-
for (const QByteArray &name : qAsConst(updateNames)) {
163+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
164+
for (const QByteArray &name : std::as_const(updateNames)) {
165+
#else
166+
for (const QByteArray &name : qAsConst(updateNames)) {
167+
#endif
158168
if (updateService(name)) {
159169
queryNames.insert(name);
160170
}
@@ -178,7 +188,11 @@ void BrowserPrivate::onMessageReceived(const Message &message)
178188
// Build and send a query for all of the SRV and TXT records
179189
if (queryNames.count()) {
180190
Message queryMessage;
181-
for (const QByteArray &name : qAsConst(queryNames)) {
191+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
192+
for (const QByteArray &name : std::as_const(queryNames)) {
193+
#else
194+
for (const QByteArray &name : qAsConst(queryNames)) {
195+
#endif
182196
Query query;
183197
query.setName(name);
184198
query.setType(SRV);
@@ -240,7 +254,11 @@ void BrowserPrivate::onQueryTimeout()
240254
// Include PTR records for the target that are already known
241255
QList<Record> records;
242256
if (cache->lookupRecords(query.name(), PTR, records)) {
243-
for (const Record &record : qAsConst(records)) {
257+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
258+
for (const Record &record : std::as_const(records)) {
259+
#else
260+
for (const Record &record : qAsConst(records)) {
261+
#endif
244262
message.addRecord(record);
245263
}
246264
}
@@ -253,8 +271,11 @@ void BrowserPrivate::onServiceTimeout()
253271
{
254272
if (ptrTargets.count()) {
255273
Message message;
256-
for (const QByteArray &target : qAsConst(ptrTargets)) {
257-
274+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
275+
for (const QByteArray &target : std::as_const(ptrTargets)) {
276+
#else
277+
for (const QByteArray &target : qAsConst(ptrTargets)) {
278+
#endif
258279
// Add a query for PTR records
259280
Query query;
260281
query.setName(target);
@@ -264,7 +285,11 @@ void BrowserPrivate::onServiceTimeout()
264285
// Include PTR records for the target that are already known
265286
QList<Record> records;
266287
if (cache->lookupRecords(target, PTR, records)) {
267-
for (const Record &record : qAsConst(records)) {
288+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
289+
for (const Record &record : std::as_const(records)) {
290+
#else
291+
for (const Record &record : qAsConst(records)) {
292+
#endif
268293
message.addRecord(record);
269294
}
270295
}

0 commit comments

Comments
 (0)