【问题标题】:ISO C++ forbids declaration of ... with no typeISO C++ 禁止声明 ... 没有类型
【发布时间】:2011-08-21 02:31:23
【问题描述】:

我正在使用 C++ 为 maemo 制作 Qt 移动应用程序。

我有我的班级声明,但我收到此错误:

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

上面的错误是什么意思?

【问题讨论】:

  • 你忘了说哪一行准确地触发了错误并给出了准确的错误文本。这很重要。
  • 亲爱的 Jon.. 我在构建过程中遇到错误,导致它的行是 QGeoPositionInfoSource *gpsSource; 在我的 .h 文件中...上面显示了确切的错误文本...
  • 可能QGeoPositionInfoSource 在某个命名空间中(抱歉,我使用了 QT)。你可以检查一下。
  • 你确定 真的被包含了并且它包含QGeoPositionInfoSource 类的声明吗?您可以通过在 PhoneHelper 类声明之前添加前向声明 class QGeoPositionInfoSource; 来检查它。

标签: c++ qt header-files maemo qt-mobility


【解决方案1】:

我没有看到我必须像这样使用 QtMobility 命名空间using namespace QtMobility;

【讨论】:

  • 我建议使用 QtMobility::QGeoPositionInfoSource 不要在标题中包含整个命名空间。
  • 将 using 子句放入头文件只会导致问题。完全限定类型名称。
  • 您应该在标头中使用前向声明,这对于命名空间来说并非易事:namespace QtMobility { class QGeoPositionInfoSource; }。这可能看起来很奇怪,但它是前向声明命名空间成员的正确方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多