2

I'm using C++ to make a Qt mobile application for maemo.

I have my class declaration, but I get this error:

ISO C++ forbids declaration of 'QGeoPositionInfoSource' with no type

My code is following:

phonehelper.h

#ifndef PHONEHELPER_H
#define PHONEHELPER_H

#include <QObject>
#include <QGeoPositionInfoSource>


class PhoneHelper : public QObject
{
    Q_OBJECT

public:
    explicit PhoneHelper(QObject *parent = 0);
    void GetGPSData(const char * callbackSlot);

private:
    /*
     * The error occures here on the line below */
    QGeoPositionInfoSource *gpsSource;         // PROBLEM HERE

private slots:
    void positionUpdated(const QGeoPositionInfo &info);
};

#endif // PHONEHELPER_H

phonehelper.cpp

#include "phonehelper.h"

PhoneHelper::PhoneHelper(QObject *parent) :
    QObject(parent)
{
}

PhoneHelper::GetGPSData(const char *callbackSlot)
{
    gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
             if (gpsSource) {
                 connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                         this, SLOT(positionUpdated(QGeoPositionInfo)));
                 connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                         this, SLOT(callbackSlot(QGeoPositionInfo)));
                 gpsSource->startUpdates();
             }
}

PhoneHelper::positionUpdated(const QGeoPositionInfo &info)
{
        gpsSource->stopUpdates();
        delete gpsSource;
}

Project.pro

DEPLOYMENTFOLDERS = # file1 dir1

symbian:TARGET.UID3 = 0xE0EEBE99


symbian:TARGET.CAPABILITY += NetworkServices

# MOBILITY variable.
CONFIG += mobility
MOBILITY += location

SOURCES += main.cpp mainwindow.cpp \
    phonehelper.cpp
HEADERS += mainwindow.h \
    phonehelper.h
FORMS += mainwindow.ui


include(deployment.pri)
qtcAddDeployment()

What does the above error mean?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Łukasz W.
  • 9,538
  • 5
  • 38
  • 63
  • 3
    You forgot to say which line exactly triggers the error and give the exact error text. Which is kind of important. – Jon May 08 '11 at 12:18
  • Dear Jon.. I get error during build, the line that couses it is `QGeoPositionInfoSource *gpsSource;` in my .h file... The exact error text is presented above... – Łukasz W. May 08 '11 at 12:24
  • 1
    Probably `QGeoPositionInfoSource` is in some namespace (sorry, I've used QT). You could check that. – Kiril Kirov May 08 '11 at 12:32
  • 2
    Are you sure that is really included and that it contains declaration for `QGeoPositionInfoSource` class? You can check it by adding forward declaration `class QGeoPositionInfoSource;` just before `PhoneHelper` class declaration. – beduin May 08 '11 at 12:36

1 Answers1

4

I did not see that I had to use QtMobility namespace like this using namespace QtMobility;

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Łukasz W.
  • 9,538
  • 5
  • 38
  • 63
  • 4
    I'd recommend using `QtMobility::QGeoPositionInfoSource` not to include the whole namespace in the header. – Kiril Kirov May 08 '11 at 12:50
  • 3
    Putting a using clause into a header file will just lead to problems down the road. Fully qualify the type name,. – Martin York May 08 '11 at 13:19
  • You should use a forward declaration in headers, which isn't trivial for namespaces: `namespace QtMobility { class QGeoPositionInfoSource; }`. This may look weird, but it's the correct way to forward-declare namespace members. – MSalters May 09 '11 at 09:24