QtBluetooth 支持 Ubuntu Touch

QtBluetooth 支持 Ubuntu Touch

我喜欢构建一个基于 qml 并支持蓝牙的应用程序。我的代码在 Ubuntu SDK 中的桌面套件上运行良好,但在 BQ Aquaris 4.5 上失败,并显示错误消息“未安装模块“QtBluetooth””。

我的问题:

  • 是否有计划在不久的将来在 Ubuntu Phone 上支持 QtBluetooth?
  • 如果没有:是否可以手动安装 QtBluetooth?
  • 如果没有:QtBluetooth 有替代品吗?

如果有人想尝试,只需在 ubuntu sdk 中创建一个 qml 项目并复制/粘贴以下代码:

import QtQuick 2.4
import Ubuntu.Components 1.2
import Ubuntu.Components 1.2 as Toolkit
import Ubuntu.Components.ListItems 1.0 as ListItem
import QtBluetooth 5.2


MainView {
    width: units.gu(40)
    height: units.gu(60)

    Page {
        title: i18n.tr("Bluetooth")
        property BluetoothService currentService

        BluetoothDiscoveryModel {
            id: btModel
            running: false
            discoveryMode: BluetoothDiscoveryModel.DeviceDiscovery
            onDiscoveryModeChanged: console.log("Discovery mode: " + discoveryMode)
            onServiceDiscovered: console.log("Found new service " + service.deviceAddress + " " + service.deviceName + " " + service.serviceName);
            onDeviceDiscovered: console.log("New device: " + device)
            onErrorChanged: {
                switch (btModel.error) {
                case BluetoothDiscoveryModel.PoweredOffError:
                    console.log("Error: Bluetooth device not turned on"); break;
                case BluetoothDiscoveryModel.InputOutputError:
                    console.log("Error: Bluetooth I/O Error"); break;
                case BluetoothDiscoveryModel.InvalidBluetoothAdapterError:
                    console.log("Error: Invalid Bluetooth Adapter Error"); break;
                case BluetoothDiscoveryModel.NoError:
                    break;
                default:
                    console.log("Error: Unknown Error"); break;
                }
            }
       }

        Button{
            id: scanner
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.margins: units.gu(2)
            width: parent.width / 2
            text: "Scan"
            onClicked: btModel.running=true
        }

        ActivityIndicator {
            id: busy
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.margins: units.gu(2)
            running: btModel.running
        }

        ListItem.ItemSelector {
            anchors.top: busy.bottom //+ units.gu(15)
            anchors.margins: units.gu(2)
            text: i18n.tr("Bluetooth Devices:")
            expanded: true

            model: btModel
            delegate: Toolkit.OptionSelectorDelegate { text: deviceName; subText: remoteAddress }
        }
    }
}

相关内容