Search code examples
qtqt-mobility

error: ‘QtMobility’ is not a namespace-name


I am trying to compile: http://wiki.forum.nokia.com/index.php/Fetching_a_map_tile_in_Qt_using_Google_Maps

I am using Qt-Mobility 1.2 with Qt 4.7 on OpenSuse 11.2

The errors I am receiving are:

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

My .pro file contains:

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

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

QT += network
CONFIG += mobility
MOBILITY = location

The error is reported in the header file, which I have shown as follows:

#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;
}

Please guide.


Solution

  • You'll need to include at least one QtMobility header to be able to use that namespace.

    Also that using namespace declaration is not the recommended way anymore. Use:

     QTM_USE_NAMESPACE
    

    instead (see QtMobility QuickStart).