c – QObject:缺少vtable链接错误

前端之家收集整理的这篇文章主要介绍了c – QObject:缺少vtable链接错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道这个问题已被问过很多次,但我在这里找不到解决方案,也没有在谷歌找到解决方案.

这是我的头文件@H_301_3@

#ifndef MAINCONTROLLER_H
#define MAINCONTROLLER_H

#include <QSettings>
#include <QDebug>
#include <QDir>
#include <QObject>

#include "PhTools/PhString.h"
#include "PhStrip/PhStripDoc.h"

class MainController : public QObject
{
    Q_OBJECT

public:
    explicit MainController(QObject *parent = 0);
    void loadSettings();
    PhString getLastFile();
    void setLastFile(PhString fileName);
    bool openDoc(PhString fileName);

signals:
    void docChanged();

private:
    QSettings * _settings;
    PhStripDoc * _doc;

};

#endif // MAINCONTROLLER_H

我的CPP档案:@H_301_3@

#include "MainController.h"


MainController::MainController(QObject *parent) :
    QObject(parent)
{
    _doc = new PhStripDoc();
    loadSettings();
}
void MainController::loadSettings()
{
    _settings = new QSettings(QDir::homePath() + "/Library/Preferences/com.me.me.plist",QSettings::NativeFormat);

    getLastFile();
}

PhString MainController::getLastFile()
{
    qDebug() << "lastfile :" << _settings->value("last_file","").toString();
    return _settings->value("last_file").toString();
}

bool MainController::openDoc(PhString fileName)
{
    bool succeed = _doc->openDX(fileName);
    if (succeed)
        emit docChanged();
    return succeed;
}

void MainController::setLastFile(PhString filename)
{
    _settings->setValue("last_file",filename);
}

这是错误日志:@H_301_3@

Undefined symbols for architecture x86_64:
  "MainController::docChanged()",referenced from:
      MainController::openDoc(QString) in MainController.o
  "vtable for MainController",referenced from:
      MainController::MainController(QObject*) in MainController.o
      MainController::MainController(QObject*) in MainController.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command Failed with exit code 1 (use -v to see invocation)

它可能来自信号,但我不确定……@H_301_3@

解决方法

您需要在源文件的末尾包含此行:

#include“MainController.moc”@H_301_3@

或者,您也可以使用您的构建系统来处理这个问题,但这可能更容易.@H_301_3@

原文链接:https://www.f2er.com/c/115636.html

猜你在找的C&C++相关文章