Add a helper function to more easily access ZeroConf txt records

pull/294/head
Michael Zanetti 2020-05-18 11:35:45 +02:00
parent 9af820b696
commit 17eb0fc697
2 changed files with 13 additions and 0 deletions

View File

@ -116,6 +116,18 @@ QStringList ZeroConfServiceEntry::txt() const
return m_txt; return m_txt;
} }
/*! Returns the txt entry of the given \a key of this \l{ZeroConfServiceEntry}.*/
QString ZeroConfServiceEntry::txt(const QString &key) const
{
foreach (const QString &txtEntry, m_txt) {
QStringList parts = txtEntry.split('=');
if (parts.length() == 2 && parts.first() == key) {
return parts.last();
}
}
return QString();
}
/*! Returns true if this \l{ZeroConfServiceEntry} is valid.*/ /*! Returns true if this \l{ZeroConfServiceEntry} is valid.*/
bool ZeroConfServiceEntry::isValid() const bool ZeroConfServiceEntry::isValid() const
{ {

View File

@ -52,6 +52,7 @@ public:
quint16 port() const; quint16 port() const;
QAbstractSocket::NetworkLayerProtocol protocol() const; QAbstractSocket::NetworkLayerProtocol protocol() const;
QStringList txt() const; QStringList txt() const;
QString txt(const QString &key) const;
bool isValid() const; bool isValid() const;