Skip to content

Commit a592b0b

Browse files
committed
Differentiate between Qt >= 6.7 and less
1 parent ae6b4da commit a592b0b

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
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 17
4959
CXX_STANDARD_REQUIRED ON
5060
DEFINE_SYMBOL QT_NO_SIGNALS_SLOTS_KEYWORDS
5161
DEFINE_SYMBOL QT_NO_FOREACH

src/src/browser.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ bool BrowserPrivate::updateService(const QByteArray &fqName)
9191
QList<Record> txtRecords;
9292
if (cache->lookupRecords(fqName, TXT, txtRecords)) {
9393
QMap<QByteArray, QByteArray> attributes;
94-
for (const Record &record : std::as_const(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
9599
for (auto i = record.attributes().constBegin();
96100
i != record.attributes().constEnd(); ++i) {
97101
attributes.insert(i.key(), i.value());
@@ -156,7 +160,11 @@ void BrowserPrivate::onMessageReceived(const Message &message)
156160
// For each of the services marked to be updated, perform the update and
157161
// make a list of all missing SRV records
158162
QSet<QByteArray> queryNames;
159-
for (const QByteArray &name : std::as_const(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
160168
if (updateService(name)) {
161169
queryNames.insert(name);
162170
}
@@ -180,7 +188,11 @@ void BrowserPrivate::onMessageReceived(const Message &message)
180188
// Build and send a query for all of the SRV and TXT records
181189
if (queryNames.count()) {
182190
Message queryMessage;
183-
for (const QByteArray &name : std::as_const(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
184196
Query query;
185197
query.setName(name);
186198
query.setType(SRV);
@@ -242,7 +254,11 @@ void BrowserPrivate::onQueryTimeout()
242254
// Include PTR records for the target that are already known
243255
QList<Record> records;
244256
if (cache->lookupRecords(query.name(), PTR, records)) {
245-
for (const Record &record : std::as_const(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
246262
message.addRecord(record);
247263
}
248264
}
@@ -255,8 +271,11 @@ void BrowserPrivate::onServiceTimeout()
255271
{
256272
if (ptrTargets.count()) {
257273
Message message;
258-
for (const QByteArray &target : std::as_const(ptrTargets)) {
259-
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
260279
// Add a query for PTR records
261280
Query query;
262281
query.setName(target);
@@ -266,7 +285,11 @@ void BrowserPrivate::onServiceTimeout()
266285
// Include PTR records for the target that are already known
267286
QList<Record> records;
268287
if (cache->lookupRecords(target, PTR, records)) {
269-
for (const Record &record : std::as_const(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
270293
message.addRecord(record);
271294
}
272295
}

0 commit comments

Comments
 (0)