<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.5.0, 2013-09-06T18:40:12. -->
+<!-- Written by Qt Creator 2.5.0, 2013-09-06T21:17:23. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Target.DesktopTarget</value>
- <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
#include "ui_deviceagent.h"
#include <QtNetwork>
#include <QtGui>
-#include <QTemporaryFile>
+#include <QXmlStreamReader>
#include <string.h>
DeviceAgent::DeviceAgent(QWidget *parent) :
tcpServer = new QTcpServer(this);
QHostAddress address = QHostAddress::LocalHost;
tcpServer->listen(address, 3333);
- file = new QTemporaryFile();
- file->open();
- out = new QTextStream (file);
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
void DeviceAgent::acceptConnection()
{
+ QString string;
clientConnection = tcpServer->nextPendingConnection();
+
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
connect(clientConnection, SIGNAL(error(QAbstractSocket::SocketError)),
-//! [3]
this, SLOT(displayError(QAbstractSocket::SocketError)));
-// connect(clientConnection, SIGNAL(readyRead()), this, SLOT(dataFromClient()));
+
connect(clientConnection, SIGNAL(disconnected()), this, SLOT(endFromClient()));
char data[10];
if (numData == -1) {
clientConnection->close();
- endFromClient();
+ endFromClient(string);
return;
}
memcpy(currentData, data, numData);
-
- *out << currentData;
+ string.append(currentData);
memset(data, 0, sizeof(data));
memset(currentData, 0, sizeof(currentData));
numData = clientConnection->read(data, sizeof(data));
}
-
-
}
else {
clientConnection->close();
- endFromClient();
+ endFromClient(string);
return;
}
}
}
-void DeviceAgent::endFromClient()
+void DeviceAgent::endFromClient(QString string)
{
clientConnection->deleteLater();
- file->close();
+ QXmlStreamReader xml;
+ xml.addData(string);
+
+ while (!xml.atEnd() && !xml.hasError())
+ {
+ xml.readNext();
+ if (xml.isStartElement())
+ {
+ QString name = xml.name().toString();
+ if (name == "rawData")
+ {
+ ui->lcdNumber->display(xml.readElementText());
+ }
+ }
+ }
+ if (xml.hasError())
+ {
+ }
+ else if (xml.atEnd())
+ {
+ }
}
void DeviceAgent::displayError(QAbstractSocket::SocketError socketError)
<string>DeviceAgent</string>
</property>
<widget class="QWidget" name="centralWidget">
- <widget class="QTextEdit" name="textEdit">
+ <widget class="QLCDNumber" name="lcdNumber">
<property name="geometry">
<rect>
- <x>70</x>
- <y>60</y>
- <width>241</width>
+ <x>30</x>
+ <y>30</y>
+ <width>301</width>
<height>51</height>
</rect>
</property>
+ <property name="lineWidth">
+ <number>1</number>
+ </property>
+ <property name="numDigits">
+ <number>10</number>
+ </property>
+ <property name="mode">
+ <enum>QLCDNumber::Dec</enum>
+ </property>
+ <property name="segmentStyle">
+ <enum>QLCDNumber::Filled</enum>
+ </property>
+ </widget>
+ <widget class="QTextBrowser" name="textBrowser">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>120</y>
+ <width>291</width>
+ <height>91</height>
+ </rect>
+ </property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">