2011-05-18 50 views
0

我試圖編譯:http://wiki.forum.nokia.com/index.php/Fetching_a_map_tile_in_Qt_using_Google_Maps錯誤:「QtMobility的」不是一個命名空間名字

我使用QtMobility的1.2使用Qt 4.7在openSUSE 11.2

我收到的錯誤是:

MainWindow.h:7: error: ‘QtMobility’ is not a namespace-name 
MainWindow.h:7: error: expected namespace-name before ‘;’ token 
MainWindow.h:10: error: expected class-name before ‘{’ token 
In file included from /opt/qtsdk-2010.05/qt/include/QtCore/qcoreapplication.h:47, 
       from /opt/qtsdk-2010.05/qt/include/QtGui/qapplication.h:45, 
       from /opt/qtsdk-2010.05/qt/include/QtGui/QApplication:1, 
       from main.cpp:2: 
/opt/qtsdk-2010.05/qt/include/QtCore/qeventloop.h:51: error: expected initializer before ‘QtCoreModule’ 
make: *** [main.o] Error 1 

我.pro文件包含:

TEMPLATE = app 
TARGET = 
DEPENDPATH += . 
INCLUDEPATH += . 

HEADERS += MainWindow.h 
SOURCES += main.cpp MainWindow.cpp 

QT += network 
CONFIG += mobility 
MOBILITY = location 

報道在標題連接錯誤我已經顯示如下:

#include <QtNetwork/QNetworkAccessManager> 
#include <QtNetwork/QNetworkReply> 
#include <QPaintEvent> 
#include <QPixmap> 

using namespace QtMobility; 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    MainWindow(); 
    void paintEvent(QPaintEvent* paintEvent); 

public slots: 
    void handleNetworkData(QNetworkReply* reply); 

private: 
    void fetchMap(const QSize& size, qreal latitude, qreal longitude); 

private: 
    QNetworkAccessManager networkAccessManager; 
    QPixmap mapPixmap; 
} 

請指導。

回答

2

您需要至少包含一個QtMobility頭才能使用該名稱空間。

此外,using namespace聲明不再是推薦的方式。使用:

​​3210

改爲(參見QtMobility QuickStart)。

+1

正如Mat所說:首先添加一個QtMobility頭文件,然後QTM_USE_NAMESPACE – Ikky 2011-05-18 08:35:05

+0

感謝@lkky和@Mat,我實際上已經在發佈之前查找了這個鏈接,但無法弄清楚它的確切含義是_we必須包括類QtMobility_中的頭文件:redface:沒有仔細閱讀它! – 2011-05-18 08:48:53

+0

@Anisha刪除'using namespace QtMobility;'並再試一次 – emaillenin 2011-05-18 09:50:06