我无法使传感器在华硕T100变压器上工作。

磁力计和指南针无法启动,并且加速度计上的数值我是假的(总是x = 0,y = 9.8,z = 0)。

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

第一个文本编辑:

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

第二文字编辑:
ven. juin 6 14:56:41 2014
Acceleration:  x = 0
y = 9.8
z = 0

Compass: 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);
}

给我吗 :
Sensor: QAmbientLightSensor
Sensor: QAccelerometer
Sensor: QTiltSensor
Sensor: QOrientationSensor
Sensor: QRotationSensor

QCompass在哪里? Q磁力计为什么QAccelerometer是伪造的? :'(

这是我的简化测试代码,仅使用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

代码:
#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());
}

最佳答案

现在的解决方案是破解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)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt
}

删除此行:
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt

然后打开src / plugins / sensors / winrt / winrt.pro并添加以下行:
win32-msvc2012|win32-msvc2013: LIBS += -lruntimeobject

最后运行qmake,make / nmake,make / nmake安装
(向Google查询有关如何构建的更多信息)

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

要获取更多信息,请遵循:
  • 链接到错误:https://bugreports.qt-project.org/browse/QTBUG-39590
  • 链接至补丁:https://codereview.qt-project.org/#/c/87370/
  • 10-07 15:36