0

I'm trying added such class to a project^

//Emitter.h
#ifndef EMITTER_H
#define EMITTER_H

#include <QObject>
#include <QDBusInterface>
#include <QDBusAbstractAdaptor>
#include <QDBusVariant>

class Emitter:public QObject
{
    Q_OBJECT
public:
    Emitter();

private:
    QDBusInterface * m_interface;
    QString m_interfaceName;
};

#endif // EMITTER_H

and

//Emitter.cpp 
#include "CESMEmitter.moc"
#include "Emitter.h"
Emitter::Emitter( QObject * parent )
     : QObject( parent )
{
}

CESMEmitter.moc file I received by using moc like this:

moc CESMEmitter.h > CESMEmitter.moc

After trying to build with Makefile I received an error, sayng that Qt include files were not found.

So I added variable

QT_STUFF = -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtDBus -I/usr/include/qt4 -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lQtDBus -lpthread 

And applied it.

The include files were found, but other errors arised:

error: undefined reference to `QObject::QObject(QObject*)'
error: undefined reference to `qt_assert(char const*, char const*, int)'
error: undefined reference to `QString::shared_null'
error: undefined reference to `QString::shared_null'

Can anyone please advise?

4

1 回答 1

0

尽管它可能会起作用,但您不应该只有一个QT_STUFF变量。您需要一个单独的用于编译(使用-Iand -D)和链接(with -L/-l)。您也可能缺少编译所需的定义。Qt 4 需求

-DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED

并且对于您使用的所有 Qt 库都类似。Qt 5 需要

-DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB

您还确定链接器不会抱怨缺少 Qt 库吗?

至少让 qmake 生成可以调整的初始 Makefile 可能更容易。

于 2013-09-11T17:44:48.463 回答