summaryrefslogtreecommitdiffstats
path: root/examples/corelib/ipc/localfortuneclient
diff options
context:
space:
mode:
Diffstat (limited to 'examples/corelib/ipc/localfortuneclient')
-rw-r--r--examples/corelib/ipc/localfortuneclient/CMakeLists.txt36
-rw-r--r--examples/corelib/ipc/localfortuneclient/client.cpp29
-rw-r--r--examples/corelib/ipc/localfortuneclient/client.h11
-rw-r--r--examples/corelib/ipc/localfortuneclient/main.cpp4
4 files changed, 40 insertions, 40 deletions
diff --git a/examples/corelib/ipc/localfortuneclient/CMakeLists.txt b/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
index c6b5d53e37..f3f2b13f92 100644
--- a/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
+++ b/examples/corelib/ipc/localfortuneclient/CMakeLists.txt
@@ -1,16 +1,13 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
cmake_minimum_required(VERSION 3.16)
project(localfortuneclient LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/ipc/localfortuneclient")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
+qt_standard_project_setup()
+
qt_add_executable(localfortuneclient
client.cpp client.h
main.cpp
@@ -21,15 +18,22 @@ set_target_properties(localfortuneclient PROPERTIES
MACOSX_BUNDLE TRUE
)
-target_link_libraries(localfortuneclient PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Network
- Qt::Widgets
+target_link_libraries(localfortuneclient PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Network
+ Qt6::Widgets
)
install(TARGETS localfortuneclient
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET localfortuneclient
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/corelib/ipc/localfortuneclient/client.cpp b/examples/corelib/ipc/localfortuneclient/client.cpp
index 31f8cf475b..b71409560b 100644
--- a/examples/corelib/ipc/localfortuneclient/client.cpp
+++ b/examples/corelib/ipc/localfortuneclient/client.cpp
@@ -1,14 +1,19 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtWidgets>
-#include <QtNetwork>
-
#include "client.h"
+#include <QDialogButtonBox>
+#include <QGridLayout>
+#include <QGuiApplication>
+#include <QMessageBox>
+#include <QTimer>
+
+using namespace Qt::StringLiterals;
+
Client::Client(QWidget *parent)
: QDialog(parent),
- hostLineEdit(new QLineEdit("fortune")),
+ hostLineEdit(new QLineEdit(u"fortune"_s)),
getFortuneButton(new QPushButton(tr("Get Fortune"))),
statusLabel(new QLabel(tr("This examples requires that you run the "
"Local Fortune Server example as well."))),
@@ -28,7 +33,7 @@ Client::Client(QWidget *parent)
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
in.setDevice(socket);
- in.setVersion(QDataStream::Qt_5_10);
+ in.setVersion(QDataStream::Qt_6_0);
connect(hostLineEdit, &QLineEdit::textChanged,
this, &Client::enableGetFortuneButton);
@@ -58,20 +63,14 @@ void Client::requestNewFortune()
void Client::readFortune()
{
- if (blockSize == 0) {
- // Relies on the fact that QDataStream serializes a quint32 into
- // sizeof(quint32) bytes
- if (socket->bytesAvailable() < (int)sizeof(quint32))
- return;
- in >> blockSize;
- }
-
- if (socket->bytesAvailable() < blockSize || in.atEnd())
- return;
+ in.startTransaction();
QString nextFortune;
in >> nextFortune;
+ if (!in.commitTransaction())
+ return;
+
if (nextFortune == currentFortune) {
QTimer::singleShot(0, this, &Client::requestNewFortune);
return;
diff --git a/examples/corelib/ipc/localfortuneclient/client.h b/examples/corelib/ipc/localfortuneclient/client.h
index c7275252fe..b4c949a21a 100644
--- a/examples/corelib/ipc/localfortuneclient/client.h
+++ b/examples/corelib/ipc/localfortuneclient/client.h
@@ -4,15 +4,12 @@
#ifndef CLIENT_H
#define CLIENT_H
-#include <QDialog>
#include <QDataStream>
+#include <QDialog>
+#include <QLabel>
+#include <QLineEdit>
#include <QLocalSocket>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QLineEdit;
-class QPushButton;
-QT_END_NAMESPACE
+#include <QPushButton>
class Client : public QDialog
{
diff --git a/examples/corelib/ipc/localfortuneclient/main.cpp b/examples/corelib/ipc/localfortuneclient/main.cpp
index 3c2a7b284c..f52807ec48 100644
--- a/examples/corelib/ipc/localfortuneclient/main.cpp
+++ b/examples/corelib/ipc/localfortuneclient/main.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-
#include "client.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);