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

时间:2014-02-22 09:09:15

标签: qt compilation qml

我在让qm的QSensors类工作时遇到了麻烦,我真的找不到任何有用的教程或faq如何做到这一点。我已经在qt quick中使用了他们已经使用的示例应用程序,并且我已经尝试使用我在网上可以找到关于此主题的所有资源来创建我自己的应用程序但无济于事。

任何人都可以帮助我完成在qml应用程序中使用QSensors所需的步骤。或者指出我正确的方向,一步一步的指导成功编译到android.I'm编译Android 8在Windows 8任何重要。

感谢先进的帮助

回应以下评论:

如果我包含

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:\Qt\Qt5.2.1\5.2.1\Src\qtsensors\src\imports\sensors

# 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

中又拿了一个例子

on my 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 个答案:

答案 0 :(得分:1)

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

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

    QT + =传感器

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

  3. ###更新###

    尝试这一点,看看你是否从Accelometer获得读数(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)

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