summaryrefslogtreecommitdiffstats
path: root/examples/network/threadedfortuneserver
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network/threadedfortuneserver')
-rw-r--r--examples/network/threadedfortuneserver/CMakeLists.txt33
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp10
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.cpp4
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.h4
4 files changed, 26 insertions, 25 deletions
diff --git a/examples/network/threadedfortuneserver/CMakeLists.txt b/examples/network/threadedfortuneserver/CMakeLists.txt
index 02a7cb9474..8fc8cc416d 100644
--- a/examples/network/threadedfortuneserver/CMakeLists.txt
+++ b/examples/network/threadedfortuneserver/CMakeLists.txt
@@ -4,16 +4,10 @@
cmake_minimum_required(VERSION 3.16)
project(threadedfortuneserver LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/threadedfortuneserver")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
+qt_standard_project_setup()
+
qt_add_executable(threadedfortuneserver
dialog.cpp dialog.h
fortuneserver.cpp fortuneserver.h
@@ -26,15 +20,22 @@ set_target_properties(threadedfortuneserver PROPERTIES
MACOSX_BUNDLE TRUE
)
-target_link_libraries(threadedfortuneserver PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Network
- Qt::Widgets
+target_link_libraries(threadedfortuneserver PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Network
+ Qt6::Widgets
)
install(TARGETS threadedfortuneserver
- 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 threadedfortuneserver
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/network/threadedfortuneserver/dialog.cpp b/examples/network/threadedfortuneserver/dialog.cpp
index 675f5d6520..9449cab5fa 100644
--- a/examples/network/threadedfortuneserver/dialog.cpp
+++ b/examples/network/threadedfortuneserver/dialog.cpp
@@ -26,12 +26,12 @@ Dialog::Dialog(QWidget *parent)
}
QString ipAddress;
- QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ const QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
// use the first non-localhost IPv4 address
- for (int i = 0; i < ipAddressesList.size(); ++i) {
- if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
- ipAddressesList.at(i).toIPv4Address()) {
- ipAddress = ipAddressesList.at(i).toString();
+
+ for (const QHostAddress &entry : ipAddressesList) {
+ if (entry != QHostAddress::LocalHost && entry.toIPv4Address()) {
+ ipAddress = entry.toString();
break;
}
}
diff --git a/examples/network/threadedfortuneserver/fortunethread.cpp b/examples/network/threadedfortuneserver/fortunethread.cpp
index 89a2acc550..8bef57599e 100644
--- a/examples/network/threadedfortuneserver/fortunethread.cpp
+++ b/examples/network/threadedfortuneserver/fortunethread.cpp
@@ -6,7 +6,7 @@
#include <QtNetwork>
//! [0]
-FortuneThread::FortuneThread(int socketDescriptor, const QString &fortune, QObject *parent)
+FortuneThread::FortuneThread(qintptr socketDescriptor, const QString &fortune, QObject *parent)
: QThread(parent), socketDescriptor(socketDescriptor), text(fortune)
{
}
@@ -25,7 +25,7 @@ void FortuneThread::run()
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
- out.setVersion(QDataStream::Qt_4_0);
+ out.setVersion(QDataStream::Qt_6_5);
out << text;
//! [3] //! [4]
diff --git a/examples/network/threadedfortuneserver/fortunethread.h b/examples/network/threadedfortuneserver/fortunethread.h
index e93a67a37a..7dae6f2e12 100644
--- a/examples/network/threadedfortuneserver/fortunethread.h
+++ b/examples/network/threadedfortuneserver/fortunethread.h
@@ -13,7 +13,7 @@ class FortuneThread : public QThread
Q_OBJECT
public:
- FortuneThread(int socketDescriptor, const QString &fortune, QObject *parent);
+ FortuneThread(qintptr socketDescriptor, const QString &fortune, QObject *parent);
void run() override;
@@ -21,7 +21,7 @@ signals:
void error(QTcpSocket::SocketError socketError);
private:
- int socketDescriptor;
+ qintptr socketDescriptor;
QString text;
};
//! [0]