Ошибка компиляции Qt Creator для QSensor - PullRequest
0 голосов
/ 05 августа 2011

Я новичок в разработке на Qt / Symbian (я из iOS) и не могу понять ошибку этого компилятора:

Во-первых, это ошибка, которую я получаю:

/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&)':

Вот мой заголовочный файл:

#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

Вот файл реализации:

#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(QGeoPositionInfo 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
}

Если кто-нибудь может объяснить мне, что происходит,Я был бы очень благодарен.

1 Ответ

0 голосов
/ 05 августа 2011

Согласно документации ( здесь ) readingChanged сигнал не имеет никаких параметров. Вы должны использовать

connect(m_magnetometer, SIGNAL(readingChanged()), this, SLOT(magnetometerReadingChanged()));, а затем получить показание из свойства reading.

...