summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Oberst <[email protected]>2025-07-03 15:55:35 +0200
committerDennis Oberst <[email protected]>2025-07-03 19:45:55 +0200
commite81b5d59ad405208f20636cfddcaab330d37f0d2 (patch)
tree829b11cabd75ae6c34d883902d9dc83a36bc45b7
parent6a78b3404527a3f765ab5821c0c09ceb005ee101 (diff)
chat example: various enhancementsHEADdev
This patch includes: - Show available server ports dynamically. Qt built without SSL support should not show the https port. - Add an early note about the prerequisites for running the example so that users are guided from early on. - Use std::cout in combination with std::endl to flush the buffer. QtCreator doesn't print when simply using "\n". Pick-to: 6.10 6.9 6.8 Change-Id: I4eb7f6fbc1474508af2a88a3313cf94325a63657 Reviewed-by: Alexey Edelev <[email protected]>
-rw-r--r--examples/grpc/chat/client/LoginView.qml23
-rw-r--r--examples/grpc/chat/client/chatengine.cpp12
-rw-r--r--examples/grpc/chat/client/chatengine.h1
-rw-r--r--examples/grpc/chat/doc/src/chat.qdoc2
-rw-r--r--examples/grpc/chat/server/main.cpp8
5 files changed, 28 insertions, 18 deletions
diff --git a/examples/grpc/chat/client/LoginView.qml b/examples/grpc/chat/client/LoginView.qml
index 28c8c863..1c079b50 100644
--- a/examples/grpc/chat/client/LoginView.qml
+++ b/examples/grpc/chat/client/LoginView.qml
@@ -139,7 +139,7 @@ Rectangle {
Item { Layout.fillHeight: true }
Text {
- text: qsTr("Client IP: ")
+ text: qsTr("Detected IPs for This Machine:")
color: "gray"
font.bold: true
}
@@ -158,18 +158,15 @@ Rectangle {
color: "gray"
font.bold: true
}
- Text {
- Layout.leftMargin: 20
- text: "65002 (https)"
- color: "gray"
- font.italic: true
- }
- Text {
- Layout.leftMargin: 20
- Layout.bottomMargin: 20
- text: "65003 (http)"
- color: "gray"
- font.italic: true
+ Repeater {
+ model: ChatEngine.displayServerPorts()
+ Text {
+ required property string modelData
+ Layout.leftMargin: 20
+ text: modelData
+ color: "gray"
+ font.italic: true
+ }
}
Text {
diff --git a/examples/grpc/chat/client/chatengine.cpp b/examples/grpc/chat/client/chatengine.cpp
index 2c223385..7a617894 100644
--- a/examples/grpc/chat/client/chatengine.cpp
+++ b/examples/grpc/chat/client/chatengine.cpp
@@ -175,7 +175,17 @@ QList<QString> ChatEngine::findLocalIps()
return out;
}
-Q_INVOKABLE QString ChatEngine::getSchemeSymbol()
+QList<QString> ChatEngine::displayServerPorts()
+{
+ return {
+#if QT_CONFIG(ssl)
+ "65002 (https)",
+#endif
+ "65003 (http)",
+ };
+}
+
+QString ChatEngine::getSchemeSymbol()
{
#ifdef USE_EMOJI_FONT
const auto s = m_hostUri.scheme();
diff --git a/examples/grpc/chat/client/chatengine.h b/examples/grpc/chat/client/chatengine.h
index 8d5a7f96..50f30741 100644
--- a/examples/grpc/chat/client/chatengine.h
+++ b/examples/grpc/chat/client/chatengine.h
@@ -52,6 +52,7 @@ public:
Q_INVOKABLE static void openUrl(const QByteArray &url);
Q_INVOKABLE static QList<QString> findLocalIps();
+ Q_INVOKABLE static QList<QString> displayServerPorts();
Q_INVOKABLE QString getSchemeSymbol();
UserStatusModel *userStatusModel() noexcept { return m_userStatusModel.get(); }
diff --git a/examples/grpc/chat/doc/src/chat.qdoc b/examples/grpc/chat/doc/src/chat.qdoc
index 6d0e9811..1421b4e2 100644
--- a/examples/grpc/chat/doc/src/chat.qdoc
+++ b/examples/grpc/chat/doc/src/chat.qdoc
@@ -28,6 +28,8 @@
\li Visualizing QtProtobuf messages in a QML ListView.
\endlist
+ \note Make sure to read the prerequisites in \l{Running the Example}.
+
\section1 Protobuf Schema
The Protobuf schema defines the structure of messages and services used in
diff --git a/examples/grpc/chat/server/main.cpp b/examples/grpc/chat/server/main.cpp
index 3d54c070..6f406eff 100644
--- a/examples/grpc/chat/server/main.cpp
+++ b/examples/grpc/chat/server/main.cpp
@@ -128,7 +128,7 @@ public:
if (std::find(m_activeClients.begin(), m_activeClients.end(), client) != m_activeClients.end())
return false;
- std::cout << "login: " << client << ", " << client->name() << '\n';
+ std::cout << "login: " << client << ", " << client->name() << std::endl;
m_activeClients.push_back(client);
// Notify all clients including the connecting one about the new login
@@ -155,7 +155,7 @@ public:
std::unique_lock lock(m_activeClientsMtx);
if (const auto it = std::find(m_activeClients.begin(), m_activeClients.end(), client);
it != m_activeClients.end()) {
- std::cout << "logout: " << client << ", " << client->name() << '\n';
+ std::cout << "logout: " << client << ", " << client->name() << std::endl;
m_activeClients.erase(it);
return true;
}
@@ -370,8 +370,8 @@ int main(int /* argc */, char * /* argv */[])
//! [server-ssl]
builder.RegisterService(&service);
server = builder.BuildAndStart();
- std::cout << "Server listening on https://" << QtGrpcChatService::httpsAddress() << '\n';
- std::cout << "Server listening on http://" << QtGrpcChatService::httpAddress() << '\n';
+ std::cout << "Server listening on https://" << QtGrpcChatService::httpsAddress() << std::endl;
+ std::cout << "Server listening on http://" << QtGrpcChatService::httpAddress() << std::endl;
}
server->Wait();
}