ios - qml插件中的SensorGesture无法正常工作

标签 ios qt qml qt5 qtquick2

我正在关注this tutorial以检测电话的晃动。这是iOS应用开发的一部分。

import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtMultimedia 5.0
import QtGraphicalEffects 1.0
import QtSensors 5.0 as Sensors

SceneBase {
    id: screen

///*** Code of Interest ***///

    Sensors.SensorGesture {
        id: sensorGesture
        enabled: true
        gestures : ["QtSensors.shake"]

        onDetected: {
          console.log("phone shake detected")
        }
    }

/// ************************* ///

    Sensors.Gyroscope {
        id: gyro
        dataRate: 10
        active: true

        onReadingChanged: {
            if (reading.y > 1100){
                console.log("rapid motion detected")
            }
        }
    }

    //... bunch of other code
}

当与Sensors有关的代码被注释掉时,所有其他Sensors.SensorGesture都可以正常工作。但是,当取消注释该代码时,会出现以下错误。
Could not load  QtQuick2Plugin(0x146a5b80)
Could not load  QtQuick2WindowPlugin(0x146a7df0)
Could not load  QMultimediaDeclarativeModule(0x146a4020)
Could not load  QtQuickLayoutsPlugin(0x146a8120)
Could not load  QtSensorsDeclarativeModule(0x146aa6d0)
Could not load  QtQuickControlsPlugin(0x146aa870)
Could not load  QQmlLocalStoragePlugin(0x146aa9c0)
Could not load  QtQuick2ParticlesPlugin(0x146aa9e0)
Could not load  AVFServicePlugin(0x146aabf0)
Could not load  AVFMediaPlayerServicePlugin(0x146aac20)
Could not load  AudioCaptureServicePlugin(0x145a83e0)
Could not load  CoreAudioPlugin(0x145a9410)
Could not load  QM3uPlaylistPlugin(0x145a7ff0)

Could not load  QDDSPlugin(0x145a8ae0)
Could not load  QICNSPlugin(0x145a92c0)
Could not load  QICOPlugin(0x145a8760)
Could not load  QJp2Plugin(0x145a8a50)
Could not load  QMngPlugin(0x145a8e60)
Could not load  QTgaPlugin(0x145a8f30)
Could not load  QTiffPlugin(0x145a8fb0)
Could not load  QWbmpPlugin(0x145a9320)
Could not load  genericSensorPlugin(0x145a8da0)
Could not load  IOSSensorPlugin(0x145a8e30)
Could not load  QtQuick2Plugin(0x146a5b80)
Could not load  QTcpServerConnection(0x145a82e0)
Could not load  QGenericEnginePlugin(0x145a87f0)
Could not load  QSQLiteDriverPlugin(0x145a8970)
Could not load  QIOSIntegrationPlugin(0x14539070)

请帮我。

最佳答案

从5.13版本开始,iOS的Qt不支持传感器手势

请参阅兼容性图:https://doc.qt.io/qt-5/compatmap.html

我设法通过此扩展名解决了这个问题,该扩展名在.mm文件中链接到Qt应用程序:

#import“UIKit / UIKit.h”

@implementation UIWindow(WoboqWindow)

extern void sendShakeDetectedToRootObject();
-(void)motionEnded:(UIEventSubtype)motion
withEvent:(UIEvent *)event {
NSLog(@“motionEnded%@”,event);

如果(motion == UIEventSubtypeMotionShake)
{
NSLog(@“摇一摇!”);
sendShakeDetctedToRootObject();
}
}

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@“motionBegan%@”,event);
}

@结束

使用这个主要的main.cpp:

void sendShakeDetectedToRootObject(){
QMetaObject::invokeMethod(rootObject,“shakeDetected”);
}

您从QML引擎获得的rootObject。

关于ios - qml插件中的SensorGesture无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31166919/

相关文章:

c++ - 模型的QML TreeView

iphone - NSNotification 问题

ios - 使用Xcode 10旧版版本进行归档和提交

c++ - QTcpSocket 写入数据结构

qt - QMake:为 iOS App 指定自定义 Info.plist 文件

c++ - 使用动态创建的选项卡元素在 C++ 和 QML 之间进行绑定(bind)

qt - 如何在 QML 中查询键盘修饰符?

ios - 调用电话下载Android/iPhone app

ios - 如何在 SwiftUI 中将 Binding<String?> 转换为 Binding<String>

qt - 在 Qt Creator 中创建 Win32 应用程序