From 8fe7490c610fc34abf8afda8c8017d4e6433164c Mon Sep 17 00:00:00 2001 From: Ionutz Borcoman Date: Thu, 24 Feb 2011 21:40:34 +0200 Subject: [PATCH] Read socket data if available. --- src/mainwindow.cpp | 22 +++++++++++++++++----- src/mainwindow.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 320f7fd..e152515 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -14,10 +14,10 @@ #include "setupdialog.h" #include "json.h" -#include -#include -#include -#include +#include +#include +#include +#include #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK) #include @@ -189,15 +189,20 @@ ConnectedState::ConnectedState(QAbstractButton *button, QTcpSocket* socket, QSta { assignProperty(button, "text", "Disconnect"); assignProperty(button, "enabled", true); - } void ConnectedState::onEntry(QEvent */*event*/) { qDebug("ConnectedState::onEntry"); + connect(m_socket, SIGNAL(readyRead()), this, SLOT(onSocketData())); connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError))); + + QTextStream stream(m_socket); + stream << JsonEngine().playerGetActivePlayers(); + + qDebug("ConnectedState::onEntry - request sent"); } void ConnectedState::onExit(QEvent */*event*/) @@ -211,6 +216,13 @@ void ConnectedState::onSocketError(QAbstractSocket::SocketError) qDebug("ConnectedState::onSocketError: %s", qPrintable(m_socket->errorString())); } +void ConnectedState::onSocketData() +{ + QTextStream stream(m_socket); + QString msg = stream.readAll(); + qDebug("ConnectedState::onSocketData: %s", qPrintable(msg)); +} + ///////////////////////////////////////////////////////////////////// // DisconnectingState::DisconnectingState(QAbstractButton *button, QTcpSocket* socket, QState *parent) diff --git a/src/mainwindow.h b/src/mainwindow.h index e8c488c..beb9299 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -58,6 +58,7 @@ public: private slots: void onSocketError(QAbstractSocket::SocketError err); + void onSocketData(); signals: void disconnected(); -- 1.7.9.5