Jump to content
  • Advertisement
Sign in to follow this  

Qt: help using moc

This topic is 3335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

     LCDRange(QWidget *parent = 0);

     int value() const;

 public slots:
     void setValue(int value);

     void valueChanged(int newValue);

     QSlider *slider;


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"
#error "The header file 'lcdrange.h' doesn't include <QObject>."
#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.)"

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[] = {

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;

void LCDRange::valueChanged(int _t1)
    void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
    QMetaObject::activate(this, &staticMetaObject, 0, _a);
I am using windows in case it's relevant. Thanks.

Share this post

Link to post
Share on other sites
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"

Share this post

Link to post
Share on other sites
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 --help
moc: Invalid argument
Usage: 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

Share this post

Link to post
Share on other sites
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?


[Edited by - Antonym on October 28, 2009 10:47:07 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!