PDA

View Full Version : Error when compiling moc files for newly added classes



tiqt_beginner
24th September 2012, 10:38
Hi Qt-Experts,

I am a newbie in QT development. I am trying to introduce new position info source class which is a derived class of the QGeoPositionInfoSource. This derived class would be making communication with the GPS device through a customer GPS software. I am having a difficult time in compiling this sample class to do this activity. I keep getting below error when I compile the code

c_qgeopositioninfosource_linux_p.o ../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:48: error: âQGeoPositionInfoSourceLinuxâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:49: error: âQGeoPositionInfoSourceâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:57: error: âQGeoPositionInfoSourceLinuxâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:57: error: non-member function âconst QMetaObject* metaObject()â cannot have cv-qualifier
/usr/include/qt4/QtCore/qobject.h: In function âconst QMetaObject* metaObject()â:
/usr/include/qt4/QtCore/qobject.h:296: error: âQScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > QObject::d_ptrâ is protected
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:59: error: within this context
/usr/include/qt4/QtCore/qobject.h:296: error: invalid use of non-static data member âQObject::d_ptrâ
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:59: error: from this location
/usr/include/qt4/QtCore/qobject.h:296: error: âQScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > QObject::d_ptrâ is protected
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:59: error: within this context
/usr/include/qt4/QtCore/qobject.h:296: error: invalid use of non-static data member âQObject::d_ptrâ
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:59: error: from this location
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp: At global scope:
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:62: error: âQGeoPositionInfoSourceLinuxâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp: In function âvoid* qt_metacast(const char*)â:
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: expected type-specifier before âQGeoPositionInfoSourceLinuxâ
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: expected â>â before âQGeoPositionInfoSourceLinuxâ
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: expected â(â before âQGeoPositionInfoSourceLinuxâ
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: âQGeoPositionInfoSourceLinuxâ was not declared in this scope
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: expected primary-expression before â>â token
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: invalid use of âthisâ in non-member function
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:66: error: expected â)â before â;â token
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:67: error: âQGeoPositionInfoSourceâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp: At global scope:
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:70: error: âQGeoPositionInfoSourceLinuxâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp: In function âint qt_metacall(QMetaObject::Call, int, void**)â:
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:72: error: âQGeoPositionInfoSourceâ has not been declared
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:77: error: âstartUpdatesâ was not declared in this scope
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:78: error: âstopUpdatesâ was not declared in this scope
../../build/Debug/QtLocation/moc/moc_qgeopositioninfosource_linux_p.cpp:79: error: ârequestUpdateâ was not declared in this scope


My qgeopositioninfosource_linux_p.h is as below:

#ifndef QGEOPOSITIONINFOSOURCELINUX_H
#define QGEOPOSITIONINFOSOURCELINUX_H
#include "qgeopositioninfosource.h"

QTM_BEGIN_NAMESPACE

class QGeoPositionInfoSourceLinux : public QGeoPositionInfoSource
{
Q_OBJECT

public:
QGeoPositionInfoSourceLinux(QObject *parent = 0);
virtual QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const;
virtual PositioningMethods supportedPositioningMethods() const;
virtual int minimumUpdateInterval() const;
public Q_SLOTS:
void startUpdates();
void stopUpdates();
void requestUpdate(int timeout = 5000);
};

QTM_END_NAMESPACE

#endif

I am just unable to resolve this error that is reported when compiling the moc file. Any help from QT experts to resolve this error is highly appreciated.

BR,
-Raghu

ChrisW67
24th September 2012, 22:24
Why are you trying to put your class into the Qt Mobility namespace? Did you perhaps intend this:


#ifndef QGEOPOSITIONINFOSOURCELINUX_H
#define QGEOPOSITIONINFOSOURCELINUX_H
#include "qgeopositioninfosource.h"

QTM_USE_NAMESPACE
// ^^^^^^^^^^^^^^ this

class QGeoPositionInfoSourceLinux : public QGeoPositionInfoSource
{
...
};

#endif

as described here (http://doc.qt.digia.com/qtmobility/quickstart.html). Is Qt Mobility enabled in your Pro file?

tiqt_beginner
25th September 2012, 03:38
Yes, I intend to use Qt Mobility namespace. I want the class to be built as part of the QtLocation library.

Have just added SOURCES and PRIVATE_HEADERS as below in the location.pro file.


SOURCES += qgeopositioninfosource_linux.cpp
PRIVATE_HEADERS += qgeopositioninfosource_linux_p.h