qml插件的SensorGesture不工作



我遵循本教程来检测手机的抖动。这是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.SensorGesture有关的代码时,所有其他Sensors都可以正常工作。但是,当代码被取消注释时,它会给出以下错误。

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应用程序:

#导入"UIKit/UIKit.h"@实现UIWindow(WoboqWindow(extern void sendShakeDetectedToRootObject((;-(void(motionEnded:(UIEventSubtype(运动withEvent:(UIEvent*(事件{NSLog(@"motionEnded%@",事件(;if(motion==UIEventSubtypeMotionShake({NSLog(@"摇一摇!"(;sendShakeDetctedToRootObject((;}}-(void(motionBegan:(UIEventSubtype(带有事件的运动:(UIEvent*(事件{NSLog(@"motionBegan%@",事件(;}@完

有了这个主要的.cpp:

void sendShakeDetectedToRootObject(({QMetaObject::invokeMethod(rootObject,"shakeDetected"(;}

从QML引擎获得的rootObject。

相关内容

  • 没有找到相关文章

最新更新