O MOC no QT não compilará meu arquivo de cabeçalho C ++. diz que é muito diferente
Pergunta
Ok, o WTF é isso que o MOC me diz quando tento MOC um dos meus arquivos de cabeçalho. Estou fazendo isso através do prompt de comando QT 4.5.3 e diz o seguinte:
C:\Documents and Settings\The Fuzz\Desktop\GUI2>moc App_interface.h
/****************************************************************************
** Meta object code from reading C++ file 'App_interface.h'
**
** Created: Mon Oct 12 16:58:11 2009
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.3)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "App_interface.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'App_interface.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 61
#error "This file was generated using the moc from 4.5.3. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_App_interface[] = {
// content:
2, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0 // eod
};
static const char qt_meta_stringdata_App_interface[] = {
"App_interface\0"
};
const QMetaObject App_interface::staticMetaObject = {
{ &QWidget::staticMetaObject, qt_meta_stringdata_App_interface,
qt_meta_data_App_interface, 0 }
};
const QMetaObject *App_interface::metaObject() const
{
return &staticMetaObject;
}
void *App_interface::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_App_interface))
return static_cast<void*>(const_cast< App_interface*>(this));
return QWidget::qt_metacast(_clname);
}
int App_interface::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
return _id;
}
QT_END_MOC_NAMESPACE
C:\Documents and Settings\The Fuzz\Desktop\GUI2>
alguma ideia??? Estou tentando usar a macro Q_Object.
Solução
moc
Converte seu cabeçalho de entrada em um arquivo gerado, que é impresso em sua saída. Você deve enviar sua saída para um arquivo, com um comando como:
moc App_interface.h > App_interface.h_moc
Em seguida, inclua isso.
Se você estiver usando o QMake, acredito que esse processo é automatizado.
Outras dicas
Isso também pode ajudar: você precisa herdar do QObject antes de outras classes: http://doc.trolltech.com/4.1/moc.html#multiple-neritance-requires-qobject-to-be-first.
De acordo com a resposta anterior, é muito melhor usar o QMake.
Eu recomendo fortemente usar um IDE QT Criador, em vez de construir a partir da linha de comando.