2014-02-22 41 views
0

我真的有麻煩讓QSensors類的qml工作,我真的找不到任何有用的教程或常見問題解答如何做到這一點。我已經使用了他們已經在qt中已經有的示例應用程序,並且嘗試使用我可以在網上找到的有關該主題的所有資源來做我自己的應用程序,但沒有任何結果。如何使用/部署Qt傳感器Qml應用程序到我的設備

任何人都可以幫助我,我需要能夠在我的qml應用程序中使用QSensors的步驟。或者指出我正確的方向,以一個良好的一步一步的指導,以成功編譯爲android.I'm編譯的Windows在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

在我的體內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() 
      } 
     } 

,我可以得到鞭,扭右,捻左側,捻(不是SSO很多,但多數民衆贊成也許到我自己的錯誤),掩護,拿起並且猛擊。但其他人根本沒有。其中一些並不重要,但這些是我真正需要的,沒有運氣。雙擊我什麼都沒有得到,當我做左或右懸停時,我得到一個三角洲x,y,z讀數顯示在控制檯中,但沒有luch直到事物的手勢一側。我也得到它看起來像這樣

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] 

上雙擊我什麼也沒得到。再次

感謝。

+0

什麼是實際問題? – Mitch

+0

感謝您的回覆。我已經編輯了我的帖子以迴應你的問題。 – TheMan68

回答

1

首先,你應該給出一個說明你的問題的方法來縮小它和/或某些彙編/去混合輸出

  1. 我建議你檢查你的項目文件(Qt Creator中)*。親如果它包含傳感器的支持,否則添加它如下:

    QT + =傳感器

  2. 嘗試編譯項目不同的平臺如果可以的話,並在平均時間檢查,如果傳感器庫是支持由您的目標平臺

###更新###

試試這個,看看你是從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 
       } 
      } 
     } 
    } 
} 
} 

兩者都適合我,你的例子和我修改的一個。

我的環境:贏得7 64,QT 5.2.1 QtCreator 3.0.1(MinGW的4.8 armabi-V7的Android)

目標:Android平板(愛可視70B鈦,OS 4.1)

+0

謝謝你的迴應。我已經編輯了我的帖子以迴應你的問題。 – TheMan68

+0

你能提供更多信息嗎?就像一個小例子(在qml代碼中)與您的PRO文件。感謝 – Redanium

+0

我已經添加了您在我的文章中請求的信息。謝謝 – TheMan68

相關問題