OSDN Git Service

use Q_DECLARE_TR_FUNCTIONS() instead of QObject inheritance in QHostInfoAgent
authorIvailo Monev <xakepa10@gmail.com>
Thu, 10 Dec 2020 10:07:34 +0000 (10:07 +0000)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 10 Dec 2020 10:07:34 +0000 (10:07 +0000)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/network/kernel/qhostinfo_p.h
src/network/kernel/qhostinfo_unix.cpp

index 5e656fb..9bd1287 100644 (file)
@@ -76,10 +76,9 @@ Q_SIGNALS:
     void resultsReady(const QHostInfo &info);
 };
 
-// needs to be QObject because fromName calls tr()
-class QHostInfoAgent : public QObject
+class QHostInfoAgent
 {
-    Q_OBJECT
+    Q_DECLARE_TR_FUNCTIONS(QHostInfoAgent)
 public:
     static QHostInfo fromName(const QString &hostName);
 };
index 72b3357..0654c21 100644 (file)
@@ -140,9 +140,11 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
     results.setHostName(hostName);
     if (aceHostname.isEmpty()) {
         results.setError(QHostInfo::HostNotFound);
-        results.setErrorString(hostName.isEmpty() ?
-                               QCoreApplication::translate("QHostInfoAgent", "No host name given") :
-                               QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
+        if (hostName.isEmpty()) {
+            results.setErrorString(tr("No host name given"));
+        } else {
+            results.setErrorString(tr("Invalid hostname"));
+        }
         return results;
     }