开发者

Qt Creator compile error for QSensor

开发者 https://www.devze.com 2023-03-26 07:42 出处:网络
I\'m new to Qt/Symbian development (I come from an iOS background), and I can\'t make sense of this compiler error:

I'm new to Qt/Symbian development (I come from an iOS background), and I can't make sense of this compiler error:

Firstly, this is the error I'm getting:

/Users/Dave/AR-build-simulator/../QtSDK/Simulator/QtMobility/gcc/include/QtSensors/qsensor.h:-1: In member function 'QtMobility::QMagnetometerReading& QtMobility::QMagnetometerReading::operator=(const QtMobility::QMagnetometerReading&)':

Here is my header file:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QSystemDeviceInfo>
#include <QGeoPositionInfoSource>
#include <QGeoCoordinate>
#include <QGeoPositionInfo>
#include <QMagnetometer>

QTM_USE_NAMESPACE
namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    enum ScreenOrientation {
        ScreenOrientationLockPortrait,
        ScreenOrientationLockLandscape,
        ScreenOrientationAuto
    };

    explicit MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();

    // Note that this will only have an effect on Symbian and Fremantle.
    void setOrientation(ScreenOrientation orientation);

    void showExpanded();

private slots:
    void positionUpdated(QGeoPositionInfo gpsPos);
    void magnetometerReadingChanged(QMagnetometerReading mr);
private:
    Ui::MainWindow *ui;
    void setupGeneral();

    QGeoPositionInfoSource *m_location;
    QGeoCoordinate m_coordinate;
    QMagnetometer *m_magnetometer;
    QMagnetometerReading m_magnetometerReading;
};

#endif // MAINWINDOW_H

Here is the implementation file:

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtCore/QCoreApplication>
#include <qgeopositioninfosource.h>
#include <QMessageBox>

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

void MainWindow::setupGeneral()
{
    m_location = QGeoPositionInfoSource::createDefaultSource(this);
    //Listen to gps position changes
    QObject::connect(m_location, SIGNAL(positionUpdated(QGeoPositionInfo)), this,SLOT(positionUpdated(QGeoPositionInfo)));

    //Start listening to GPS position updates
    m_location->startUpdates();

    //Start listening to magnetometer updates
    m_magnetometer = new QMagnetometer(this);
    connect(m_magnetometer, SIGNAL(readingChanged(QMagnetometerReading)), this, SLOT(magnetometerReadingChanged(QMagnetometerReading)));
    m_magnetometer->start();
}

void MainWindow::positionUpdated(QGeoPo开发者_运维问答sitionInfo gpsPos){
     m_coordinate = gpsPos.coordinate();
     if (m_coordinate.isValid()) {
            m_location->stopUpdates();
            QString longitude;
            QString latitude;
            longitude.setNum(m_coordinate.longitude());
            latitude.setNum(m_coordinate.latitude());
            QMessageBox::information(this,"latitude",latitude);
     } else {
            QMessageBox::information(this, "GPS Info", "Coordinator is not valid...");
     }
}

void MainWindow::magnetometerReadingChanged(QMagnetometerReading mr) {
    QMessageBox::information(this, "Magnetometer info", "got magnetometer reading...");
    m_magnetometerReading = mr;
    //m_magnetometerReading = new QMagnetometerReading(this);
    //m_magnetometerReading->copyValuesFrom(mr);
}

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

void MainWindow::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
    // If the version of Qt on the device is < 4.7.2, that attribute won't work
    if (orientation != ScreenOrientationAuto) {
        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
            return;
        }
    }
#endif // Q_OS_SYMBIAN

    Qt::WidgetAttribute attribute;
    switch (orientation) {
#if QT_VERSION < 0x040702
    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
    case ScreenOrientationLockPortrait:
        attribute = static_cast<Qt::WidgetAttribute>(128);
        break;
    case ScreenOrientationLockLandscape:
        attribute = static_cast<Qt::WidgetAttribute>(129);
        break;
    default:
    case ScreenOrientationAuto:
        attribute = static_cast<Qt::WidgetAttribute>(130);
        break;
#else // QT_VERSION < 0x040702
    case ScreenOrientationLockPortrait:
        attribute = Qt::WA_LockPortraitOrientation;
        break;
    case ScreenOrientationLockLandscape:
        attribute = Qt::WA_LockLandscapeOrientation;
        break;
    default:
    case ScreenOrientationAuto:
        attribute = Qt::WA_AutoOrientation;
        break;
#endif // QT_VERSION < 0x040702
    };
    setAttribute(attribute, true);
}

void MainWindow::showExpanded()
{
#ifdef Q_OS_SYMBIAN
    showFullScreen();
#elif defined(Q_WS_MAEMO_5)
    showMaximized();
#else
    show();
#endif
}

If anybody could explain to me what is going wrong, I'd be very grateful.


According to the documentation(here) readingChanged signal does not have any parameters. You should use

connect(m_magnetometer, SIGNAL(readingChanged()), this, SLOT(magnetometerReadingChanged())); and then acquire the reading from the reading property.

0

精彩评论

暂无评论...
验证码 换一张
取 消