jbagg / QtZeroConf

Qt wrapper class for ZeroConf libraries across various platforms.
Other
69 stars 51 forks source link

issue reading txtrecord of addService() #24

Closed mayurpatelgec closed 5 years ago

mayurpatelgec commented 6 years ago

I want to fetch text record of added service aka.
zcs.txt["Qt"]; --> should give me QT is best according to your info file.

but in my case, its showing failed. the hint can be mismatch data type in QMap & QByteArray; bcz qDebug () << zcs.txt(); gives me complete QMap but cant fetch the single one.. a simple example like your readme will be enough.

error: invalid types ' [const char [5]]' for array subscript.

jbagg commented 6 years ago

A patch to apply to the example that shows how to read txt records. Please close the ticket if satisfied.

--- a/example/window.cpp
+++ b/example/window.cpp
@@ -149,9 +149,12 @@ void mainWindow::stopPublishClicked()

 void mainWindow::addService(QZeroConfService zcs)
 {
+       QMap <QByteArray, QByteArray> records;
        qint32 row;
        QTableWidgetItem *cell;
-       qDebug() << "Added service: " << zcs;
+
+       records = zcs.txt();
+       qDebug() << "Added service: " << zcs << records["Qt"];
mayurpatelgec commented 5 years ago

i have not tested it but i think it will work.

thanks.. :+1:

jbagg commented 5 years ago

The markdown parser removed the template arguments. Here is the correct patch...

--- a/example/window.cpp
+++ b/example/window.cpp
@@ -149,10 +149,13 @@ void mainWindow::stopPublishClicked()

 void mainWindow::addService(QZeroConfService zcs)
 {
+       QMap<QByteArray, QByteArray> records;
        qint32 row;
        QTableWidgetItem *cell;
        qDebug() << "Added service: " << zcs;

+       records = zcs->txt();
+       qDebug() << "Added service: " << zcs << records["Qt"];