2011-05-08 165 views
1

我正在使用C++为maemo制作一个Qt移动应用程序。ISO C++禁止声明...没有类型

我有我的类声明,但我得到这个错误:

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

我的代码如下:

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() 

是什么上述错误是什么意思?

+3

你忘了说哪一行正是引发错误并给出精确的错误文本。这很重要。 – Jon 2011-05-08 12:18:35

+0

亲爱的乔恩。我构建过程中出现错误,那couses是'QGeoPositionInfoSource * gpsSource行;'在我的.h文件...确切的错误文本上面介绍... – 2011-05-08 12:24:01

+1

大概'QGeoPositionInfoSource'在一些命名空间(对不起,我用过QT)。你可以检查。 – 2011-05-08 12:32:13

回答

3

我没有看到,我不得不使用QtMobility的命名空间这样using namespace QtMobility;

+4

我建议使用'QtMobility :: QGeoPositionInfoSource'不要在头中包含整个名称空间。 – 2011-05-08 12:50:23

+3

将使用子句放入头文件只会导致出现问题。完全限定类型名称。 – 2011-05-08 13:19:36

+0

您应该在头文件中使用前向声明,这对名称空间来说并不重要:'namespace QtMobility {class QGeoPositionInfoSource; }'。这可能看起来很奇怪,但这是正确的方式来转发声明命名空间成员。 – MSalters 2011-05-09 09:24:36

相关问题