gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:32:01 25 4
gpt4 key购买 nike

我正在关注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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com