本文介绍了Qt 5.3无法使QCompass(QSensor)在Windows 8.1上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能在我的华硕变压器T100上使用传感器。



磁力计和罗盘不启动,我有加速度计的假值= 0,y = 9.8,z = 0)。



我总是得到相同的结果,即使我的笔记本电脑:



first text Edit:

 初始化... 
QAccelerometer连接到后端...
QAccelerometer isActive ...
Attente desdonnéescapteur ...

/ p>

  ven。 juin 6 14:56:41 2014 
加速:x = 0
y = 9.8
z = 0

罗盘:UNAVAILABLE
QMagnetometer:UNAVAILABLE

而此代码:

  QList< QByteArray> sensorList = QSensor :: sensorTypes(); 
ui-> init-> append(Sensor list length:+ QString :: number(sensorList.size())。toUtf8());
foreach(QByteArray sensorName,sensorList){
ui-> init-> append(Sensor:+ sensorName);
}

给我:

 传感器:QAmbientLightSensor 
传感器:QAccelerometer
传感器:QTiltSensor
传感器:QOrientationSensor
传感器:QRotationSensor

QCompass在哪里? QMagnetometer?为什么QAccelerometer是假的? :'(



这是我简化的测试代码,只有QCompass:



>

  #ifndef MAINWINDOW_H 
#define MAINWINDOW_H

#include< QMainWindow>

#include< QCompass>
#include< QCompassReading>


namespace Ui {
class MainWindow;
}

class MainWindow:public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget * parent = 0);
〜MainWindow );

public slots:
void update();
void error(int);

private:
Ui :: MainWindow * ui;

QCompass * compass;
QCompassReading * compass_reading;
};

#endif // MAINWINDOW_H

代码:

  #include< ; QDateTime> 
#includemainwindow.h
#includeui_mainwindow.h

#include< QMessageBox>

MainWindow :: MainWindow(QWidget * parent):
QMainWindow(parent),
ui(new Ui :: MainWindow)
{
ui-> setupUi(this);

ui-> init-> setText(Initialisation ...);

compass = new QCompass(this);
connect(compass,SIGNAL(readingChanged()),this,SLOT(update()));
connect(compass,SIGNAL(sensorError(int)),this,SLOT(error(int)));
compass-> setDataRate(1);
compass-> start()
if(compass-> isBusy()){
ui-> init-> append(QCompass is busy ...);
}
if(compass-> isConnectedToBackend()){
ui-> init-> append(QCompass is connected to backend ...);
}
if(compass-> isActive()){
ui-> init-> append(QCompass isActive ...);
}

ui-> init-> append(Waiting for sensors ...);
}

MainWindow ::〜MainWindow()
{
删除指南针;
delete ui;
}

void MainWindow :: update()
{
QString text_compass;

ui-> textEdit-> clear();

accel_reading = accel-> reading();

compass_reading = compass-> reading();
if(compass_reading!= 0){
text_compass = QDateTime :: currentDateTime()。toString()+
+\\\
Compass:azimuth =+ QString :: number > azimuth());
+\\\
calibration level =+ QString :: number(compass_reading-> calibrationLevel());

ui-> textEdit-> append(text_compass);
}
else {
text_compass =\\\
Compass:UNAVAILABLE;
ui-> textEdit-> append(text_compass);
}
}


void MainWindow :: error(int erreur){
QMessageBox :: critical(this,Erreur,Erreur num :+ QString :: number(erreur).toUtf8());
}


解决方案

hack winrt传感器插件并重建它。
(winrt的传感器后端适用于Windows 7/8桌面应用程序)。



首先git克隆插件,或者获取Qt的源代码。 >

然后打开src / plugins / sensors / sensors.pro并添加以下行:

  win32-msvc2012 | win32-msvc2013 {
isEmpty(SENSORS_PLUGINS):SENSORS_PLUGINS = winrt generic dummy
}

winrt | win32-msvc2012 | win32-msvc2013 {
isEmpty(SENSORS_PLUGINS)|包含(SENSORS_PLUGINS,winrt):SUBDIRS + = winrt
}

REMOVE this line:

  isEmpty(SENSORS_PLUGINS)|包含(SENSORS_PLUGINS,winrt):winrt:SUBDIRS + = winrt 

然后打开src / plugins / sensors / winrt / winrt.pro并添加以下行:

  win32-msvc2012 | win32-msvc2013:LIBS + = -lruntimeobject 

最后运行qmake,make / nmake,make / nmake install
(问问google有关如何构建的更多信息)



重要:运行过程应该从qtsensors.pro文件所在的目录(例如, G。 C:\Qt\5.4\Src\qtsensors)。



要获取更多信息,请按照以下步骤操作:




  • 链接到错误:

  • 链接到补丁:


I can't make sensors works on my Asus Transformer T100.

Magnetometer and Compass don't start, and I have fake value from the accelerometer (always x=0, y=9.8, z=0).

I always get the same result, even with my laptop :

first textEdit:

Initialisation...
QAccelerometer is connected to backend...
QAccelerometer isActive...
Attente des données capteur...

Second textEdit:

ven. juin 6 14:56:41 2014
Acceleration:  x = 0
y = 9.8
z = 0

Compass: UNAVAILABLE
QMagnetometer: UNAVAILABLE

And this code :

QList<QByteArray> sensorList = QSensor::sensorTypes();
ui->init->append("Sensor list length: " + QString::number(sensorList.size()).toUtf8());
foreach( QByteArray sensorName, sensorList ) {
    ui->init->append("Sensor: " + sensorName);
}

Give me :

Sensor: QAmbientLightSensor
Sensor: QAccelerometer
Sensor: QTiltSensor
Sensor: QOrientationSensor
Sensor: QRotationSensor

Where is QCompass ? QMagnetometer ? Why QAccelerometer is faked ? :'(

Here is my simplified test-code, only with QCompass :

header:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QCompass>
#include <QCompassReading>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void update();
    void error(int);

private:
    Ui::MainWindow *ui;

    QCompass *compass;
    QCompassReading *compass_reading;
};

#endif // MAINWINDOW_H

code :

#include <QDateTime>
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->init->setText("Initialisation...");

    compass = new QCompass(this);
    connect(compass, SIGNAL(readingChanged()), this, SLOT(update()));
    connect(compass, SIGNAL(sensorError(int)), this, SLOT(error(int)));
    compass->setDataRate(1);
    compass->start();
    if (compass->isBusy()) {
        ui->init->append("QCompass is busy...");
    }
    if(compass->isConnectedToBackend()) {
        ui->init->append("QCompass is connected to backend...");
    }
    if(compass->isActive()) {
        ui->init->append("QCompass isActive...");
    }

    ui->init->append("Waiting for sensors...");
}

MainWindow::~MainWindow()
{
    delete compass;
    delete ui;
}

void MainWindow::update()
{
    QString text_compass;

    ui->textEdit->clear();

    accel_reading = accel->reading();

    compass_reading = compass->reading();
    if(compass_reading != 0) {
        text_compass = QDateTime::currentDateTime().toString() +
                + "\nCompass:  azimuth = " + QString::number(compass_reading->azimuth());
                + "\ncalibration level = " + QString::number(compass_reading->calibrationLevel());

        ui->textEdit->append(text_compass);
    }
    else {
        text_compass = "\nCompass: UNAVAILABLE";
        ui->textEdit->append(text_compass);
    }
}


void MainWindow::error(int erreur) {
    QMessageBox::critical(this, "Erreur", "Erreur num : " + QString::number(erreur).toUtf8());
}
解决方案

The solution for now is to hack the winrt sensors plugin and rebuild it.(the sensors backend for winrt works for windows 7/8 desktop application).

First git clone the plugin, or get Qt's source code.

then open src/plugins/sensors/sensors.pro and add these lines :

win32-msvc2012|win32-msvc2013 {
    isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic dummy
}

winrt|win32-msvc2012|win32-msvc2013 {
    isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt
}

REMOVE this line :

isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt

Then open src/plugins/sensors/winrt/winrt.pro and add this lines :

win32-msvc2012|win32-msvc2013: LIBS += -lruntimeobject

And finally run qmake, make/nmake, make/nmake install(Ask google for more informations about how to build)

IMPORTANT : the run process should start from the directory where the qtsensors.pro file is (e. g. C:\Qt\5.4\Src\qtsensors).

To get more informations, and follow :

这篇关于Qt 5.3无法使QCompass(QSensor)在Windows 8.1上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:36