0

我正在尝试在 QCoreApplication 中获取位置更新,以下是我正在尝试的代码,但出现错误

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

代码:

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

如果我取消注释 Q_OBJECT 我得到错误:

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

0 回答 0