如何在我的设备上使用/部署Qt Sensors Qml应用程序



我很难让qml的QSensors类工作,我真的找不到任何有用的教程或常见问题解答。我使用了他们已经在qt quick中使用的示例应用程序,我试图用我在网上可以找到的关于这个主题的所有资源来制作我自己的应用程序,但没有成功。

有人能帮我完成在qml应用程序中使用QSensor所需的步骤吗。或者给我一个正确的方向,一步一步地指导我成功编译到android。我正在为windows 8上的android编译,以防这有任何重要意义。

感谢您在高级方面的帮助

针对以下评论:

如果我包括

QT += sensors
// and in my qml file
import QtSensors 5.0

然后我可以编译到我的android,但当我点击屏幕时,我收到了这个错误

D/GraphicBuffer(26197): create handle(0x761ce210) (w:720, h:1230, f:1)
D/GraphicBuffer(26197): create handle(0x761d0058) (w:720, h:1230, f:1)
D/VelocityTracker(26197): Couldn't open '/dev/touch' (No such file or directory)
D/VelocityTracker(26197): tpd read x fail: Bad file number
D/VelocityTracker(26197): tpd read y fail: Bad file number
D/dalvikvm(26197): threadid=11: bye!
D/dalvikvm(26197): threadid=11: interp stack at 0x74b26000
D/dalvikvm(26197): threadid=11: bye!

这是我的头文件

# Add more folders to ship with the application, here
folder_01.source = qml/SensorTester
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
QT += quick
QT=core gui
QT += sensors
CONFIG += plugin
CONFIG += ordered
INCLUDEPATH += C:QtQt5.2.15.2.1Srcqtsensorssrcimportssensors
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

和我的qml文件

import QtQuick 2.0
import QtQuick.Controls 1.0
import QtSensors 5.0
Rectangle {
id: gesturerect
border.width: 1
anchors.margins: 5
property string selectedGesture: ""
SensorGesture {
id: gesture
}
Text {
id: labelGesture
anchors.top: gesturerect.top
anchors.left: gesturerect.left
anchors.right: gesturerect.right
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 30
font.bold: true
text: "Gestures"
}
Rectangle {
id: gestureListRect
border.width: 1
anchors.top: labelGesture.bottom
anchors.left: gesturerect.left
anchors.right: gesturerect.right
anchors.bottom: gesturerect.bottom
anchors.margins: 5
//! [4]
ListView {
id: gestureList
//! [4]
anchors.fill: gestureListRect
anchors.margins: 5
//! [5]
model: gesture.availableGestures
//! [5]
focus: true
currentIndex: -1
delegate: gestureListDelegate
clip: true
//! [6]
}
//! [6]
Component {
id: gestureListDelegate
Rectangle {
width: gestureList.width
height: itemText.height
color: (index === gestureList.currentIndex ? "#999933" : "#FFFFFF")
Text {
id: itemText
text: model.modelData
}
MouseArea {
anchors.fill: parent
onClicked: {
gestureList.currentIndex = index
selectedGesture = model.modelData
}
}
}
}
}
}

更新的

多亏了每个人的帮助,我才使它发挥作用,但仍有一些并发症。我举了http://qt-project.org/doc/qt-5/qtsensors-shakeit-example.html的另一个例子

在我的vivo y20t:上

onDetected:{
console.debug(gesture)
label.text = gesture
if (gesture == "shake") {
window.state == "rotated" ? window.state = "default" : window.state = "rotated"
timer.start()
}
if (gesture == "whip") {
window.state == "whipped" ? window.state = "default" : window.state = "whipped"
timer.start()
}
if (gesture == "twistRight") {
window.state == "twistedR" ? window.state = "default" : window.state = "twistedR"
timer.start()
}
if (gesture == "twistLeft") {
window.state == "twistedL" ? window.state = "default" : window.state = "twistedL"
timer.start()
}
if (gesture == "cover") {
window.state == "covered" ? window.state = "default" : window.state = "covered"
timer.start()
}
if (gesture == "hover") {
window.state == "hovered" ? window.state = "default" : window.state = "hovered"
timer.start()
}
if (gesture == "turnover") {
window.state = "default"
loopy2a_mono.play();
timer.start()
}
if (gesture == "pickup") {
window.state = "default"
phone.play()
timer.start()
}
if (gesture == "slam") {
window.state == "slammed" ? window.state = "default" : window.state = "slammed"
timer.start()
}
if (gesture == "doubletap") {
window.state == "doubletapped" ? window.state = "default" : window.state = "doubletapped"
timer.start()
}
}

我可以抽打,向右扭转,向左扭转,扭转(不是很多,但这可能是我自己的错误),掩护,捡球和灌篮。但其他的根本不是。其中一些并不那么重要,但这些是我真正需要的,而且没有运气。双击我什么都没有,当我向左或向右悬停时,控制台上会显示一个delta x、y、z读数,但在手势方面没有运气。我也得到一个错误,看起来像这个

D/SensorManager(26532): framework alsps raw_data dataX=0.0 dataY=7426.0 dataZ=9571.0
D/SensorManager(26532): open file /sys/bus/platform/drivers/als_ps/sys_prox_status error
D/SensorManager(26532): echo 0 > /sys/bus/platform/drivers/als_ps/sys_prox_status
I/SurfaceTextureClient(26532): [STC::queueBuffer] (this:0x754f75b0) fps:47.44, dur:1011.90, max:41.40, min:10.39

在我的三星galaxy note 2上,除了悬停功能外,所有以上都是一样的,这是我得到的

D/SensorManager( 3161): Proximity, val = 0.0  [close]
D/SensorManager( 3161): Proximity, val = 8.0  [far]

双击我一无所获。

再次感谢。

首先,您应该举例说明您的问题以缩小它和/或一些编译/去编译输出

  1. 我建议您检查项目文件(Qt Creator)*.pro,如果它包含传感器支持,否则按如下方式添加

    QT+=传感器

  2. 如果可以的话,请尝试在不同的平台中编译您的项目,同时检查目标平台是否支持传感器库

###更新###

试试这个,看看你是否从加速度计上得到读数(x,y读数在labelGesture上更新):

import QtQuick 2.0
import QtQuick.Controls 1.0
import QtSensors 5.0 as Sensors
import QtQuick.Window 2.0
Rectangle {
id: gesturerect
width: Screen.width;
height: Screen.height
border.width: 1
anchors.margins: 5
property string selectedGesture: ""

Sensors.Accelerometer{
id:accMeter
active: true
onReadingChanged: {
var r= reading;
labelGesture.text = "x : "+ r.x +" y : " +r.y 
}
Component.onCompleted: accMeter.start()
}
Text {
id: labelGesture
anchors.top: gesturerect.top
anchors.left: gesturerect.left
anchors.right: gesturerect.right
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 30
font.bold: true
}
Rectangle {
id: gestureListRect
border.width: 1
anchors.top: labelGesture.bottom
anchors.left: gesturerect.left
anchors.right: gesturerect.right
anchors.bottom: gesturerect.bottom
anchors.margins: 5
//! [4]
ListView {
id: gestureList
//! [4]
anchors.fill: gestureListRect
anchors.margins: 5
//! [5]
model: Sensors.QmlSensors.sensorTypes()//gesture.availableGestures
//! [5]
focus: true
currentIndex: -1
delegate: gestureListDelegate
clip: true
//! [6]
}
//! [6]
Component {
id: gestureListDelegate
Rectangle {
width: gestureList.width
height: itemText.height
color: (index === gestureList.currentIndex ? "#999933" : "#FFFFFF")
Text {
id: itemText
text: model.modelData
}
MouseArea {
anchors.fill: parent
onClicked: {
gestureList.currentIndex = index
selectedGesture = model.modelData
}
}
}
}
}
}

两者都为我工作,你的例子和我修改的例子。

我的环境:win 7 64,Qt 5.2.1 QtCreator 3.0.1(MinGW 4.8 armabi-v7 Android)

目标:安卓平板电脑(Archos 70b Titanium,OS 4.1)

最新更新