Qt: help using moc

Started by
3 comments, last by mattd 14 years, 5 months ago
I am trying to use moc with the following header.

 #ifndef LCDRANGE_H
 #define LCDRANGE_H

#include <QObject>
 #include <QWidget>

 class QSlider;

 class LCDRange : public QWidget
 {
     Q_OBJECT

 public:
     LCDRange(QWidget *parent = 0);

     int value() const;

 public slots:
     void setValue(int value);

 signals:
     void valueChanged(int newValue);

 private:
     QSlider *slider;
 };

 #endif


I get the following in the command line. I am not sure what it means, did it fail or succeed? Am I supposed to do something with the code that shows up?

C:\Qt\4.5.0-vc\qt\bin>moc.exe "C:\Documents and Settings\David\Mis documentos\Vi
sual Studio 2008\Projects\Qt Project\Qt Project\lcdrange.h"
/****************************************************************************
** Meta object code from reading C++ file 'lcdrange.h'
**
** Created: Wed 28. Oct 06:25: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 "C:\Documents and Settings\David\Mis documentos\Visual Studio 2008\Proj
ects\Qt Project\Qt Project\lcdrange.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'lcdrange.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_LCDRange[] = {

 // content:
       2,       // revision
       0,       // classname
       0,    0, // classinfo
       2,   12, // methods
       0,    0, // properties
       0,    0, // enums/sets
       0,    0, // constructors

 // signals: signature, parameters, type, tag, flags
      19,   10,    9,    9, 0x05,

 // slots: signature, parameters, type, tag, flags
      43,   37,    9,    9, 0x0a,

       0        // eod
};

static const char qt_meta_stringdata_LCDRange[] = {
    "LCDRange\0\0newValue\0valueChanged(int)\0"
    "value\0setValue(int)\0"
};

const QMetaObject LCDRange::staticMetaObject = {
    { &QWidget::staticMetaObject, qt_meta_stringdata_LCDRange,
      qt_meta_data_LCDRange, 0 }
};

const QMetaObject *LCDRange::metaObject() const
{
    return &staticMetaObject
}

void *LCDRange::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_LCDRange))
        return static_cast<void*>(const_cast< LCDRange*>(this));
    return QWidget::qt_metacast(_clname);
}

int LCDRange::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: setValue((*reinterpret_cast< int(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}

// SIGNAL 0
void LCDRange::valueChanged(int _t1)
{
    void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
    QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
QT_END_MOC_NAMESPACE
I am using windows in case it's relevant. Thanks.
Advertisement
I'm not familiar with Qt, but a quick Google suggests that moc is used to generate extra code that needs to be compiled with your QObject subclass.

The code it's spitting out is that code, so you could pipe it into another file, and then #include that file in your LCDRange.cpp file, like so;

On the command line:
moc.exe "C:\Documents and Settings\David\Mis documentos\Visual Studio 2008\Projects\Qt Project\Qt Project\lcdrange.h" > "C:\Documents and Settings\David\Mis documentos\Visual Studio 2008\Projects\Qt Project\Qt Project\lcdrange-moc.cpp"

In your lcdrange.cpp (or similar):
#include "lcdrange-moc.cpp"
You're missing the "-o" switch that tells moc where to write its output. The default place is stdout, so you see it on stdout.
octarine:(976)> moc-qt4 --helpmoc: Invalid argumentUsage: moc [options] <header-file>  -o<file>           write output to file rather than stdout  -I<dir>            add dir to the include path for header files  -E                 preprocess only; do not generate meta object code  -D<macro>[=<def>]  define macro, with optional definition  -U<macro>          undefine macro  -i                 do not generate an #include statement  -p<path>           path prefix for included file  -f[<file>]         force #include, optional file name  -nw                do not display warnings  -v                 display version of moc

Stephen M. Webb
Professional Free Software Developer

Crap, I am still getting the hang of the command line and I think I screwed something up using -o. Trying to run my moc.exe now produces an error and it has a size of 0 bytes. Is there somewhere I can download the moc.exe again/recover it?

Edit: Nevermind, the problem has been fixed.

New question, does Qt have a repository? Where?

Thanks.

[Edited by - Antonym on October 28, 2009 10:47:07 AM]
http://qt.gitorious.org/qt

This topic is closed to new replies.

Advertisement