문제

I know the question have been asked tons of times but I can't find the solution here nor in google.

Here's my header file

#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

And my CPP file :

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

And here's the error log :

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)

It might come from signals but I'm not sure...

도움이 되었습니까?

해결책 2

You need to include this line at the end of your source file:

#include "MainController.moc"

Alternatively, you can also handle this with your buildsystem, but that is probably the former is easier.

다른 팁

When the Q_OBJECT macro is added after the code has already been compiled, qmake has to be run again. This will add the creation and compilation of MainController.moc to your Makefile thus preventing the linker error.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top