Unverified Commit 5b3704c6 authored by Noir's avatar Noir Committed by GitHub

Merge pull request #1288

Port Qt examples to Qt 6
parents 7831c888 a45f31aa
......@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file. The format
is based on [Keep a Changelog](https://keepachangelog.com).
## [Unreleased]
### Changed
- Since support of Qt 5 expired, we have ported the Qt examples to version 6.
Hence, building the Qt examples now requires Qt in version 6.
## [0.18.5] - 2021-07-16
### Fixed
......
......@@ -23,7 +23,7 @@ option(THREADS_PREFER_PTHREAD_FLAG "Prefer -pthread flag if available " ON)
option(CAF_ENABLE_CURL_EXAMPLES "Build examples with libcurl" OFF)
option(CAF_ENABLE_PROTOBUF_EXAMPLES "Build examples with Google Protobuf" OFF)
option(CAF_ENABLE_QT5_EXAMPLES "Build examples with the Qt5 framework" OFF)
option(CAF_ENABLE_QT6_EXAMPLES "Build examples with the Qt6 framework" OFF)
option(CAF_ENABLE_RUNTIME_CHECKS "Build CAF with extra runtime assertions" OFF)
option(CAF_ENABLE_UTILITY_TARGETS "Include targets like consistency-check" OFF)
option(CAF_ENABLE_ACTOR_PROFILER "Enable experimental profiler API" OFF)
......
......@@ -115,9 +115,9 @@ config = [
extraBuildFlags: [
'CAF_ENABLE_CURL_EXAMPLES:BOOL=ON',
'CAF_ENABLE_PROTOBUF_EXAMPLES:BOOL=ON',
'CAF_ENABLE_QT5_EXAMPLES:BOOL=ON',
'CAF_ENABLE_QT6_EXAMPLES:BOOL=ON',
'OPENSSL_ROOT_DIR:PATH=/usr/local/opt/openssl',
'Qt5_DIR:PATH=/usr/local/opt/qt/lib/cmake/Qt5',
'Qt6_DIR:PATH=/usr/local/opt/qt/lib/cmake/Qt6',
],
extraDebugBuildFlags: [
'CAF_SANITIZERS:STRING=address',
......
......@@ -55,7 +55,7 @@ Flags (use --enable-<name> to activate and --disable-<name> to deactivate):
prefer-pthread-flag prefer -pthread flag if available [ON]
curl-examples build examples with libcurl [OFF]
protobuf-examples build examples with Google Protobuf [OFF]
qt5-examples build examples with the Qt5 framework [OFF]
qt6-examples build examples with the Qt6 framework [OFF]
runtime-checks build CAF with extra runtime assertions [OFF]
utility-targets include targets like consistency-check [OFF]
actor-profiler enable experimental proiler API [OFF]
......@@ -101,7 +101,7 @@ set_build_flag() {
prefer-pthread-flag) FlagName='THREADS_PREFER_PTHREAD_FLAG' ;;
curl-examples) FlagName='CAF_ENABLE_CURL_EXAMPLES' ;;
protobuf-examples) FlagName='CAF_ENABLE_PROTOBUF_EXAMPLES' ;;
qt5-examples) FlagName='CAF_ENABLE_QT5_EXAMPLES' ;;
qt6-examples) FlagName='CAF_ENABLE_QT6_EXAMPLES' ;;
runtime-checks) FlagName='CAF_ENABLE_RUNTIME_CHECKS' ;;
utility-targets) FlagName='CAF_ENABLE_UTILITY_TARGETS' ;;
actor-profiler) FlagName='CAF_ENABLE_ACTOR_PROFILER' ;;
......
......@@ -81,10 +81,10 @@ if(TARGET CAF::io)
add_dependencies(protobuf_broker all_examples)
endif()
if(CAF_ENABLE_QT5_EXAMPLES)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
qt5_wrap_ui(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
qt5_wrap_cpp(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
if(CAF_ENABLE_QT6_EXAMPLES)
find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED)
qt6_wrap_ui(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
qt6_wrap_cpp(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
# generated headers will be in cmake build directory
add_executable(qt_group_chat
qtsupport/qt_group_chat.cpp
......@@ -94,17 +94,17 @@ if(TARGET CAF::io)
target_link_libraries(qt_group_chat
CAF::io
CAF::internal
Qt5::Core
Qt5::Gui
Qt5::Widgets)
Qt6::Core
Qt6::Gui
Qt6::Widgets)
target_include_directories(qt_group_chat PRIVATE
qtsupport
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
${Qt6Core_INCLUDE_DIRS}
${Qt6Gui_INCLUDE_DIRS}
${Qt6Widgets_INCLUDE_DIRS})
if (CMAKE_VERSION VERSION_LESS 3.8)
message(STATUS "Note: build fails if Qt5 sets incompatible -std=ARG flag")
message(STATUS "Note: build fails if Qt6 sets incompatible -std=ARG flag")
else()
set_property(TARGET qt_group_chat PROPERTY CXX_STANDARD 17)
endif()
......
......@@ -5,8 +5,8 @@
#include "caf/detail/scope_guard.hpp"
CAF_PUSH_WARNINGS
#include <QMessageBox>
#include <QInputDialog>
#include <QMessageBox>
CAF_POP_WARNINGS
#include "chatwidget.hpp"
......@@ -67,15 +67,13 @@ void ChatWidget::init(actor_system& system) {
}
void ChatWidget::sendChatMessage() {
auto cleanup = detail::make_scope_guard([=] {
input()->setText(QString());
});
auto cleanup = detail::make_scope_guard([=] { input()->setText(QString()); });
QString line = input()->text();
if (line.isEmpty()) {
// Ignore empty lines.
} else if (line.startsWith('/')) {
vector<string> words;
auto utf8 = line.midRef(1).toUtf8();
auto utf8 = QStringView{line}.mid(1).toUtf8();
auto sv = caf::string_view{utf8.constData(),
static_cast<size_t>(utf8.size())};
split(words, sv, is_any_of(" "));
......@@ -115,8 +113,7 @@ void ChatWidget::joinGroup() {
"Please set a name first.");
return;
}
auto gname = QInputDialog::getText(this,
"Join Group",
auto gname = QInputDialog::getText(this, "Join Group",
"Please enter a group as <module>:<id>",
QLineEdit::Normal,
"remote:chatroom@localhost:4242");
......@@ -126,9 +123,9 @@ void ChatWidget::joinGroup() {
return;
}
string mod = gname.left(pos).toUtf8().constData();
string gid = gname.midRef(pos+1).toUtf8().constData();
string gid = QStringView{gname}.mid(pos + 1).toUtf8().constData();
auto x = system().groups().get(mod, gid);
if (! x)
if (!x)
QMessageBox::critical(this, "Error", to_string(x.error()).c_str());
else
self()->send(self(), join_atom_v, std::move(*x));
......@@ -137,6 +134,6 @@ void ChatWidget::joinGroup() {
void ChatWidget::changeName() {
auto name = QInputDialog::getText(this, "Change Name",
"Please enter a new name");
if (! name.isEmpty())
if (!name.isEmpty())
send_as(as_actor(), as_actor(), set_name_atom_v, name.toUtf8().constData());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment