summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/bluetooth/btchat/CMakeLists.txt14
-rw-r--r--examples/bluetooth/btchat/btchat.pro3
-rw-r--r--examples/bluetooth/btchat/chat.cpp41
-rw-r--r--examples/bluetooth/btchat/chat.h2
4 files changed, 54 insertions, 6 deletions
diff --git a/examples/bluetooth/btchat/CMakeLists.txt b/examples/bluetooth/btchat/CMakeLists.txt
index ef578b88..6d2bd0b9 100644
--- a/examples/bluetooth/btchat/CMakeLists.txt
+++ b/examples/bluetooth/btchat/CMakeLists.txt
@@ -33,6 +33,20 @@ target_link_libraries(btchat PRIVATE
Qt::Widgets
)
+if (APPLE)
+ # Using absolute path for shared plist files is a Ninja bug workaround
+ get_filename_component(SHARED_PLIST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../shared ABSOLUTE)
+ if (IOS)
+ set_target_properties(btchat PROPERTIES
+ MACOSX_BUNDLE_INFO_PLIST "${SHARED_PLIST_DIR}/Info.cmake.ios.plist"
+ )
+ else()
+ set_target_properties(btchat PROPERTIES
+ MACOSX_BUNDLE_INFO_PLIST "${SHARED_PLIST_DIR}/Info.cmake.macos.plist"
+ )
+ endif()
+endif()
+
install(TARGETS btchat
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/bluetooth/btchat/btchat.pro b/examples/bluetooth/btchat/btchat.pro
index bbf9ed18..7e0c976f 100644
--- a/examples/bluetooth/btchat/btchat.pro
+++ b/examples/bluetooth/btchat/btchat.pro
@@ -21,5 +21,8 @@ FORMS = \
chat.ui \
remoteselector.ui
+ios: QMAKE_INFO_PLIST = ../shared/Info.qmake.ios.plist
+macos: QMAKE_INFO_PLIST = ../shared/Info.qmake.macos.plist
+
target.path = $$[QT_INSTALL_EXAMPLES]/bluetooth/btchat
INSTALLS += target
diff --git a/examples/bluetooth/btchat/chat.cpp b/examples/bluetooth/btchat/chat.cpp
index a9545cf6..288f4641 100644
--- a/examples/bluetooth/btchat/chat.cpp
+++ b/examples/bluetooth/btchat/chat.cpp
@@ -13,6 +13,12 @@
#include <QtBluetooth/qbluetoothlocaldevice.h>
#include <QtBluetooth/qbluetoothuuid.h>
+#if QT_CONFIG(permissions)
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#include <QtWidgets/qmessagebox.h>
+#endif
+
using namespace Qt::StringLiterals;
static constexpr auto serviceUuid = "e8e10f95-1a70-4b27-9ccf-02010264e9c8"_L1;
@@ -32,6 +38,35 @@ Chat::Chat(QWidget *parent)
//! [Construct UI]
ui->connectButton->setFocus();
+ initBluetooth();
+}
+
+Chat::~Chat()
+{
+ qDeleteAll(clients);
+ delete ui;
+}
+
+void Chat::initBluetooth()
+{
+#if QT_CONFIG(permissions)
+ QBluetoothPermission permission{};
+ switch (qApp->checkPermission(permission)) {
+ case Qt::PermissionStatus::Undetermined:
+ qApp->requestPermission(permission, this, &Chat::initBluetooth);
+ return;
+ case Qt::PermissionStatus::Denied:
+ QMessageBox::warning(this, tr("Missing permissions"),
+ tr("Permissions are needed to use Bluetooth. "
+ "Please grant the permissions to this "
+ "application in the system settings."));
+ qApp->quit();
+ return;
+ case Qt::PermissionStatus::Granted:
+ break; // proceed to initialization
+ }
+#endif // QT_CONFIG(permissions)
+
localAdapters = QBluetoothLocalDevice::allDevices();
if (localAdapters.size() < 2) {
ui->localAdapterBox->setVisible(false);
@@ -71,12 +106,6 @@ Chat::Chat(QWidget *parent)
//! [Get local device name]
}
-Chat::~Chat()
-{
- qDeleteAll(clients);
- delete ui;
-}
-
//! [clientConnected clientDisconnected]
void Chat::clientConnected(const QString &name)
{
diff --git a/examples/bluetooth/btchat/chat.h b/examples/bluetooth/btchat/chat.h
index 1c9d3211..d9a22ca7 100644
--- a/examples/bluetooth/btchat/chat.h
+++ b/examples/bluetooth/btchat/chat.h
@@ -40,6 +40,8 @@ private slots:
void newAdapterSelected();
+ void initBluetooth();
+
private:
int adapterFromUserSelection() const;
int currentAdapterIndex = 0;