diff --git a/mainwindow.cpp b/mainwindow.cpp
index 41f2b0b..12cfb8f 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -63,11 +63,9 @@ void MainWindow::sendCommand(QString cmd)
void MainWindow::replyFinished(QNetworkReply* reply)
{
- QString ans;
-
if(reply->error() == QNetworkReply::NoError) {
QByteArray data = reply->readAll();
- ans = QString(data);
+ mAnswer = QString(data);
} else {
qDebug() << reply->url();
qDebug() << reply->errorString();
@@ -77,7 +75,7 @@ void MainWindow::replyFinished(QNetworkReply* reply)
// check power state
QRegularExpression regexPower("(.+)");
- QRegularExpressionMatch matchPower = regexPower.match(ans);
+ QRegularExpressionMatch matchPower = regexPower.match(mAnswer);
if (matchPower.hasMatch()) {
if (matchPower.captured(1) == "On") mPowered = true;
else if (matchPower.captured(1) == "Off") mPowered = false;
@@ -85,14 +83,14 @@ void MainWindow::replyFinished(QNetworkReply* reply)
// check volume
QRegularExpression regexVolume("(.+)");
- QRegularExpressionMatch matchVolume = regexVolume.match(ans);
+ QRegularExpressionMatch matchVolume = regexVolume.match(mAnswer);
if (matchVolume.hasMatch()) {
mVolume = matchVolume.captured(1).toInt();
}
// check input
QRegularExpression regexInput("(.+)");
- QRegularExpressionMatch matchInput = regexInput.match(ans);
+ QRegularExpressionMatch matchInput = regexInput.match(mAnswer);
if (matchInput.hasMatch())
mInput = matchInput.captured(1);
@@ -225,7 +223,6 @@ void MainWindow::on_btn_spotify_clicked()
void MainWindow::on_btn_airplay_clicked()
{
- // TODO
sendCommand("IPOD");
mInput = "IPOD";
}
diff --git a/mainwindow.h b/mainwindow.h
index 3cb7d5b..a6c87f7 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -45,13 +45,14 @@ private:
const int TIME_VOL_COLLECT = 400;
const int TIME_UPDATE_STATE = 10000;
const int TIME_UPDATE_ADDRESS = 1000;
-
+
QString mAddress;
QTimer mTimerValCollect;
QTimer mTimerUpdateState;
QTimer mTimerUpdateAddress;
QSettings* mSettings = nullptr;
QNetworkAccessManager *mNetworkManager = nullptr;
+ QString mAnswer;
void sendCommand(QString cmd);
void updateUi();