summaryrefslogtreecommitdiffstats
path: root/examples/scxml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-10-14 11:22:39 +0200
committerUlf Hermann <ulf.hermann@qt.io>2016-10-14 10:34:14 +0000
commit46befdc26215c232047673e895245054f6a3079e (patch)
tree8da7ed83ac31b7ff30f3920440929f498155df8b /examples/scxml
parent952bfb59b27a10bad732055d17cd074463f6b770 (diff)
Use QByteArray rather than QString for ftpclient example
This makes the code simpler and relieves us of the need to assume any specific character encoding for the communication with the server. Change-Id: Icc31e963f95eeff4a13e69c3d25d6f0d400a9d13 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'examples/scxml')
-rw-r--r--examples/scxml/ftpclient/doc/src/ftpclient.qdoc5
-rw-r--r--examples/scxml/ftpclient/ftpcontrolchannel.cpp12
-rw-r--r--examples/scxml/ftpclient/ftpcontrolchannel.h8
-rw-r--r--examples/scxml/ftpclient/ftpdatachannel.cpp6
-rw-r--r--examples/scxml/ftpclient/ftpdatachannel.h8
-rw-r--r--examples/scxml/ftpclient/main.cpp8
6 files changed, 23 insertions, 24 deletions
diff --git a/examples/scxml/ftpclient/doc/src/ftpclient.qdoc b/examples/scxml/ftpclient/doc/src/ftpclient.qdoc
index ec71b89..b69994d 100644
--- a/examples/scxml/ftpclient/doc/src/ftpclient.qdoc
+++ b/examples/scxml/ftpclient/doc/src/ftpclient.qdoc
@@ -35,8 +35,7 @@
\e {FTP Client} uses Qt SCXML to implement a FTP client that can communicate
with a FTP service by sending FTP control messages translated from state
machine events and by translating server replies into state machine
- events. The data received from the FTP server is printed on the console as
- UTF-8 text.
+ events. The data received from the FTP server is printed on the console.
\l{RFC 959} specifies state charts for the command handling of the FTP
client. They can be easily translated into SCXML to benefit from SCXML
@@ -100,7 +99,7 @@
\section1 Communicating with an FTP Server
- We print all data retrieved from the server on the console as UTF-8 text:
+ We print all data retrieved from the server on the console:
\skipto QObject::connect(&dataChannel
\printuntil }
diff --git a/examples/scxml/ftpclient/ftpcontrolchannel.cpp b/examples/scxml/ftpclient/ftpcontrolchannel.cpp
index e90242d..c37b6e5 100644
--- a/examples/scxml/ftpclient/ftpcontrolchannel.cpp
+++ b/examples/scxml/ftpclient/ftpcontrolchannel.cpp
@@ -64,11 +64,11 @@ void FtpControlChannel::connectToServer(const QString &server)
m_socket.connectToHost(server, 21);
}
-void FtpControlChannel::command(const QString &command, const QString &params)
+void FtpControlChannel::command(const QByteArray &command, const QByteArray &params)
{
- QByteArray sendData = command.toUtf8();
+ QByteArray sendData = command;
if (!params.isEmpty())
- sendData += " " + params.toUtf8();
+ sendData += " " + params;
m_socket.write(sendData + "\r\n");
}
@@ -83,11 +83,11 @@ void FtpControlChannel::onReadyRead()
if (space != -1) {
int code = received.mid(0, space).toInt();
if (code == 0)
- emit info(QString::fromUtf8(received.mid(space + 1)));
+ emit info(received.mid(space + 1));
else
- emit reply(code, QString::fromUtf8(received.mid(space + 1)));
+ emit reply(code, received.mid(space + 1));
} else {
- emit invalidReply(QString::fromUtf8(received));
+ emit invalidReply(received);
}
}
}
diff --git a/examples/scxml/ftpclient/ftpcontrolchannel.h b/examples/scxml/ftpclient/ftpcontrolchannel.h
index a0cb95b..ce8ad72 100644
--- a/examples/scxml/ftpclient/ftpcontrolchannel.h
+++ b/examples/scxml/ftpclient/ftpcontrolchannel.h
@@ -65,7 +65,7 @@ public:
void connectToServer(const QString &server);
// Send a command to the server
- void command(const QString &command, const QString &params);
+ void command(const QByteArray &command, const QByteArray &params);
signals:
@@ -76,13 +76,13 @@ signals:
void closed();
// Informational message
- void info(const QString &info);
+ void info(const QByteArray &info);
// Reply to a previously sent command
- void reply(int code, const QString &parameters);
+ void reply(int code, const QByteArray &parameters);
// Something is wrong
- void invalidReply(const QString &reply);
+ void invalidReply(const QByteArray &reply);
private:
void onReadyRead();
diff --git a/examples/scxml/ftpclient/ftpdatachannel.cpp b/examples/scxml/ftpclient/ftpdatachannel.cpp
index b65e7f4..f0a7aa4 100644
--- a/examples/scxml/ftpclient/ftpdatachannel.cpp
+++ b/examples/scxml/ftpclient/ftpdatachannel.cpp
@@ -55,7 +55,7 @@ FtpDataChannel::FtpDataChannel(QObject *parent) : QObject(parent)
connect(&m_server, &QTcpServer::newConnection, this, [this]() {
m_socket.reset(m_server.nextPendingConnection());
connect(m_socket.data(), &QTcpSocket::readyRead, [this]() {
- emit dataReceived(QString::fromUtf8(m_socket->readAll()));
+ emit dataReceived(m_socket->readAll());
});
});
}
@@ -65,10 +65,10 @@ void FtpDataChannel::listen(const QHostAddress &address)
m_server.listen(address);
}
-void FtpDataChannel::sendData(const QString &data)
+void FtpDataChannel::sendData(const QByteArray &data)
{
if (m_socket)
- m_socket->write(data.toUtf8().replace("\n", "\r\n"));
+ m_socket->write(QByteArray(data).replace("\n", "\r\n"));
}
void FtpDataChannel::close()
diff --git a/examples/scxml/ftpclient/ftpdatachannel.h b/examples/scxml/ftpclient/ftpdatachannel.h
index 4a46373..2ca211c 100644
--- a/examples/scxml/ftpclient/ftpdatachannel.h
+++ b/examples/scxml/ftpclient/ftpdatachannel.h
@@ -65,8 +65,8 @@ public:
// Listen on a local address.
void listen(const QHostAddress &address = QHostAddress::Any);
- // Send data over the socket, as UTF-8 text.
- void sendData(const QString &data);
+ // Send data over the socket.
+ void sendData(const QByteArray &data);
// Close the connection.
void close();
@@ -80,8 +80,8 @@ public:
signals:
- // The FTP server has sent some data. We assume UTF-8 text for now.
- void dataReceived(const QString &data);
+ // The FTP server has sent some data.
+ void dataReceived(const QByteArray &data);
private:
QTcpServer m_server;
diff --git a/examples/scxml/ftpclient/main.cpp b/examples/scxml/ftpclient/main.cpp
index 46e7e51..3a99bd4 100644
--- a/examples/scxml/ftpclient/main.cpp
+++ b/examples/scxml/ftpclient/main.cpp
@@ -76,9 +76,9 @@ int main(int argc, char *argv[])
FtpDataChannel dataChannel;
FtpControlChannel controlChannel;
- // Print all data retrieved from the server on the console as UTF-8 text.
- QObject::connect(&dataChannel, &FtpDataChannel::dataReceived, [](const QString &data) {
- std::cout << data.toUtf8().constData();
+ // Print all data retrieved from the server on the console.
+ QObject::connect(&dataChannel, &FtpDataChannel::dataReceived, [](const QByteArray &data) {
+ std::cout << data.constData();
});
// Translate server replies into state machine events.
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
// Translate commands from the state machine into FTP control messages.
ftpClient.connectToEvent("submit.cmd", &controlChannel,
[&controlChannel](const QScxmlEvent &event) {
- controlChannel.command(event.name().mid(11), event.data().toString());
+ controlChannel.command(event.name().mid(11).toUtf8(), event.data().toByteArray());
});
// Commands to be sent