summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorTamas Martinec <tamas.martinec@symbio.com>2021-02-22 14:10:51 +0200
committerTamas Martinec <tamas.martinec@symbio.com>2021-02-23 10:04:09 +0200
commitc2b6cf8c7566db6d18cdb779e848ec4bd1cbd8d7 (patch)
tree3dc8591f42f68cb20cc98ebf0343f54c15e991c8 /examples
parent63be910b2e080bfa4d7f9e1c540cfe47f861e6d5 (diff)
QtScxml: Improve ftpclient example
- Added more error handling - Added more debug info - Added example usage - Fixed output not showing on windows Pick-to: 6.1 Task-number: QTBUG-89834 Change-Id: I4245a33fed7f738007bdc0b3495951a89d3c896d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/scxml/ftpclient/CMakeLists.txt2
-rw-r--r--examples/scxml/ftpclient/ftpcontrolchannel.cpp16
-rw-r--r--examples/scxml/ftpclient/ftpcontrolchannel.h3
-rw-r--r--examples/scxml/ftpclient/main.cpp5
4 files changed, 21 insertions, 5 deletions
diff --git a/examples/scxml/ftpclient/CMakeLists.txt b/examples/scxml/ftpclient/CMakeLists.txt
index f5e1175..61ec653 100644
--- a/examples/scxml/ftpclient/CMakeLists.txt
+++ b/examples/scxml/ftpclient/CMakeLists.txt
@@ -23,7 +23,7 @@ qt_add_executable(ftpclient
main.cpp
)
set_target_properties(ftpclient PROPERTIES
- WIN32_EXECUTABLE TRUE
+ WIN32_EXECUTABLE FALSE
MACOSX_BUNDLE TRUE
)
target_link_libraries(ftpclient PUBLIC
diff --git a/examples/scxml/ftpclient/ftpcontrolchannel.cpp b/examples/scxml/ftpclient/ftpcontrolchannel.cpp
index 5f58105..1a0067d 100644
--- a/examples/scxml/ftpclient/ftpcontrolchannel.cpp
+++ b/examples/scxml/ftpclient/ftpcontrolchannel.cpp
@@ -49,6 +49,7 @@
****************************************************************************/
#include "ftpcontrolchannel.h"
+#include <QCoreApplication>
FtpControlChannel::FtpControlChannel(QObject *parent) : QObject(parent)
{
@@ -59,6 +60,8 @@ FtpControlChannel::FtpControlChannel(QObject *parent) : QObject(parent)
connect(&m_socket, &QAbstractSocket::connected, this, [this]() {
emit opened(m_socket.localAddress(), m_socket.localPort());
});
+ connect(&m_socket, &QAbstractSocket::errorOccurred,
+ this, &FtpControlChannel::error);
}
void FtpControlChannel::connectToServer(const QString &server)
@@ -85,12 +88,21 @@ void FtpControlChannel::onReadyRead()
int space = received.indexOf(' ');
if (space != -1) {
int code = received.mid(0, space).toInt();
- if (code == 0)
+ if (code == 0) {
+ qDebug() << "Info received: " << received.mid(space + 1);
emit info(received.mid(space + 1));
- else
+ } else {
+ qDebug() << "Reply received: " << received.mid(space + 1);
emit reply(code, received.mid(space + 1));
+ }
} else {
emit invalidReply(received);
}
}
}
+
+void FtpControlChannel::error(QAbstractSocket::SocketError error)
+{
+ qWarning() << "Socket error:" << error;
+ QCoreApplication::exit();
+}
diff --git a/examples/scxml/ftpclient/ftpcontrolchannel.h b/examples/scxml/ftpclient/ftpcontrolchannel.h
index 092f2a9..c9b22a2 100644
--- a/examples/scxml/ftpclient/ftpcontrolchannel.h
+++ b/examples/scxml/ftpclient/ftpcontrolchannel.h
@@ -67,6 +67,9 @@ public:
// Send a command to the server
void command(const QByteArray &command, const QByteArray &params);
+public slots:
+ void error(QAbstractSocket::SocketError);
+
signals:
// Connection established. Local address and port are known.
diff --git a/examples/scxml/ftpclient/main.cpp b/examples/scxml/ftpclient/main.cpp
index b285077..e277661 100644
--- a/examples/scxml/ftpclient/main.cpp
+++ b/examples/scxml/ftpclient/main.cpp
@@ -64,7 +64,8 @@ struct Command {
int main(int argc, char *argv[])
{
if (argc != 3) {
- qDebug() << "Usage: ftpclient <server> <file>";
+ qWarning() << "Usage: ftpclient <server> <file>";
+ qWarning() << "For example: ftpclient ftp.gnu.org welcome.msg";
return 1;
}
@@ -79,7 +80,7 @@ int main(int argc, char *argv[])
// Print all data retrieved from the server on the console.
QObject::connect(&dataChannel, &FtpDataChannel::dataReceived,
[](const QByteArray &data) {
- std::cout << data.constData();
+ std::cout << data.constData() << std::flush;
});
// Translate server replies into state machine events.