QGeoPositionInfo not working in QCoreApplication

503 Views Asked by At

I'm trying to get the position updates in QCoreApplication, Following is the code i'm trying but i'm getting error as

QObject::connect: Cannot connect (null)::positionUpdated(QGeoPositionInfo) to QObject::positionUpdated(QGeoPositionInfo)

Code:

#include <QCoreApplication>
#include <QDebug>
#include <QObject>
#include <QtCore>


class MyClass : public QObject
{
//    Q_OBJECT
public:
    MyClass(QObject *parent = 0)
        : QObject(parent)
    {
        qDebug() << "In class";

        QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
        qDebug() << source;
            connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                    this, SLOT(positionUpdated(QGeoPositionInfo)));
            source->startUpdates();
    }

private slots:
    void positionUpdated(const QGeoPositionInfo &info)
    {
        qDebug() << "Position updated:" << info;
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    qDebug("Qt running !");

    MyClass *objmyclass = new MyClass;

    return a.exec();
}

If i uncomment the Q_OBJECT i get error as:

:-1: error: the vtable symbol may be undefined because the class is missing its key function
0

There are 0 best solutions below