diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp index 282d6127c22..d1b7ce1e783 100644 --- a/examples/network/dnslookup/dnslookup.cpp +++ b/examples/network/dnslookup/dnslookup.cpp @@ -13,7 +13,7 @@ #include -static int typeFromParameter(QStringView type) +static std::optional 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 type = typeFromParameter(typeParameter)) { + query->type = *type; + } else { *errorMessage = "Bad record type: " + typeParameter; return CommandLineError; } - query->type = static_cast(type); } const QStringList positionalArguments = parser.positionalArguments();