summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-02-27 17:36:01 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2023-03-02 12:08:10 +0100
commitb300c6b777cda86782b35976fa8babdc238984ce (patch)
tree6324775121764cfb8baa7d2eab7f1a7f223fe76d
parent5e16397a2cabd963c183a722c6daff6b2a32eada (diff)
DNS Lookup: Use std::optional instead of casting enum to int
Task-number: QTBUG-108873 Pick-to: 6.5 Change-Id: I0bd5dc004154c1c4026be2feb6187c53e5e77801 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r--examples/network/dnslookup/dnslookup.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp
index 84afeaaf02..183f191727 100644
--- a/examples/network/dnslookup/dnslookup.cpp
+++ b/examples/network/dnslookup/dnslookup.cpp
@@ -13,7 +13,7 @@
#include <stdio.h>
-static int typeFromParameter(QStringView type)
+static std::optional<QDnsLookup::Type> typeFromParameter(QStringView type)
{
if (type.compare(u"a", Qt::CaseInsensitive) == 0)
return QDnsLookup::A;
@@ -33,7 +33,7 @@ static int typeFromParameter(QStringView type)
return QDnsLookup::SRV;
if (type.compare(u"txt", Qt::CaseInsensitive) == 0)
return QDnsLookup::TXT;
- return -1;
+ return std::nullopt;
}
//! [0]
@@ -79,12 +79,12 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu
if (parser.isSet(typeOption)) {
const QString typeParameter = parser.value(typeOption);
- const int type = typeFromParameter(typeParameter);
- if (type < 0) {
+ if (std::optional<QDnsLookup::Type> type = typeFromParameter(typeParameter)) {
+ query->type = *type;
+ } else {
*errorMessage = "Bad record type: " + typeParameter;
return CommandLineError;
}
- query->type = static_cast<QDnsLookup::Type>(type);
}
const QStringList positionalArguments = parser.positionalArguments();