Qt 5.3 无法使 QCompass (QSensor) 在 Windows 8.1 上运行



我不能让传感器在我的华硕变压器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在哪里?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>
#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。修改并添加以下行:
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。并添加以下行:

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

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

重要:运行进程应该从qtsensors所在的目录开始。

配置文件是(例如C:Qt5.4Srcqtsensors)。

获取更多信息,请关注:

  • 漏洞链接:https://bugreports.qt-project.org/browse/QTBUG-39590
  • 补丁链接:https://codereview.qt-project.org/#/c/87370/

相关内容

  • 没有找到相关文章

最新更新