Seite 1 von 2

eigenartiger compilerfehler?

Verfasst: 4. März 2007 18:14
von slash-ex
ich weiß beim besten willen nicht warum er meinen slot nicht akzeptieren will?! eigentlich stimmt doch alles? weiß jemand was ich falsch gemacht habe?

Code: Alles auswählen

#ifndef QUNIT_H
#define QUNIT_H

#include <QtGui>
#include <iostream> 

class QGraphicsSceneMouseEvent;

class QUnit : public QGraphicsItem
{
	Q_OBJECT
private:
	int unit_size;
	//QColor unit_color;
	QList<QPointF> *motion_buffer;
	QTimer *motion_timer;

	void connector();

public:
	QUnit(QGraphicsItem *parent = 0, int size = 20);
	//~QUnit();

	QRectF boundingRect() const;
	QPainterPath shape() const;
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

	QList<QPointF> *last_pos();
	QList<QGraphicsItem*> check_collision();

public slots:
	void setMotionBuffer();

protected:
	//QVariant itemChange(GraphicsItemChange change, const QVariant &value);

	void mousePressEvent(QGraphicsSceneMouseEvent *event);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};

#endif 

Code: Alles auswählen

QUnit::QUnit(QGraphicsItem *parent, int size) : QGraphicsItem(parent)
{
	setFlags(ItemIsSelectable | ItemIsMovable);		//item will be drag and drop'able
	
	motion_buffer = new QList<QPointF>;

	motion_timer = new QTimer;
	QUnit::connector();

	unit_size = size;
}

void QUnit::connector()
{
	QObject::connect(motion_timer, SIGNAL(timeout() ), this, SLOT(setMotionBuffer() ) );
	motion_timer->start(100);
}

void QUnit::setMotionBuffer()
{
	std::cout<<"set new unit position"<<std::endl;
	motion_buffer->append(this->pos() );
}

...

Code: Alles auswählen

error: no matching function for call to ‘QObject::connect(QTimer*&, const char [11], QUnit* const, const char [19])’

Verfasst: 4. März 2007 18:38
von BartSimpson
Ein Blick in die Doku würde dir verraten, das QGraphicsItem nicht von QObject erbt.

Verfasst: 4. März 2007 18:47
von slash-ex
bin ich doof, aber connect ist doch eine funktion von qobject? und ein auskommentiertes q_object bringt den selben fehler?! darüber hinaus leiten sich doch "alle" klassen von qobject ab?!

Verfasst: 4. März 2007 18:49
von BartSimpson
Du kannst nur Slots bei Objekte benutzen, die von QObjekt erben!!!

Verfasst: 4. März 2007 18:53
von slash-ex
wie kann ich denn das problem lösen?! ist es nicht so, dass graphicitem zu graphicscene gehört und das wiederum von qobject abgeleitet ist?! ich kapier nicht warum das nicht gehen soll?!

Verfasst: 4. März 2007 18:56
von BartSimpson
Schau doch einfach in die Doku!!
QGraphicsItem wird von nix abgeleitet.

Verfasst: 4. März 2007 18:58
von slash-ex
hmm, du hast recht! aber was mach ich jetzt, wie komme ich nun zu meinem connect?

edit: ich denke eine vererbung von qobject kann helfen, aber irgendwie scheint mir das nicht elegant zu sein

Code: Alles auswählen

QUnit::QUnit(QGraphicsItem *parent, int size) : QGraphicsItem(parent), QObject(0)

Verfasst: 4. März 2007 19:01
von BartSimpson
Du muste dein Objekt noch zusätzlich von QObject erben lassen.
class QUnit : public QGraphicsItem,public QObject

Verfasst: 4. März 2007 19:04
von slash-ex
thx

Verfasst: 4. März 2007 19:06
von slash-ex
fuck:

Code: Alles auswählen

moc_QUnit.cpp:40: error: ‘staticMetaObject’ is not a member of ‘QGraphicsItem’
moc_QUnit.cpp: In member function ‘virtual void* QUnit::qt_metacast(const char*)’:
moc_QUnit.cpp:56: error: ‘qt_metacast’ is not a member of ‘QGraphicsItem’
moc_QUnit.cpp: In member function ‘virtual int QUnit::qt_metacall(QMetaObject::Call, int, void**)’:
moc_QUnit.cpp:61: error: ‘qt_metacall’ is not a member of ‘QGraphicsItem’
make: *** [moc_QUnit.o] Fehler 1

Verfasst: 4. März 2007 19:06
von BartSimpson
wie haste das denn jetzt gemacht?

Verfasst: 4. März 2007 19:12
von slash-ex
das sieht sehr interessant aus. mocs sind mir irgendwie so ein kleines mysterium, zum einen weil sie auch automatisch erzeugt werden ):


bei mir macht er so eine?!

Code: Alles auswählen

/****************************************************************************
** Meta object code from reading C++ file 'QUnit.h'
**
** Created: Sun Mar 4 19:06:52 2007
**      by: The Qt Meta Object Compiler version 59 (Qt 4.2.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include "battlefield/QUnit.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'QUnit.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 59
#error "This file was generated using the moc from 4.2.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

static const uint qt_meta_data_QUnit[] = {

 // content:
       1,       // revision
       0,       // classname
       0,    0, // classinfo
       1,   10, // methods
       0,    0, // properties
       0,    0, // enums/sets

 // slots: signature, parameters, type, tag, flags
       7,    6,    6,    6, 0x0a,

       0        // eod
};

static const char qt_meta_stringdata_QUnit[] = {
    "QUnit\0\0setMotionBuffer()\0"
};

const QMetaObject QUnit::staticMetaObject = {
    { &QGraphicsItem::staticMetaObject, qt_meta_stringdata_QUnit,
      qt_meta_data_QUnit, 0 }
};

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

void *QUnit::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_QUnit))
	return static_cast<void*>(const_cast<QUnit*>(this));
    if (!strcmp(_clname, "QObject"))
	return static_cast<QObject*>(const_cast<QUnit*>(this));
    return QGraphicsItem::qt_metacast(_clname);
}

int QUnit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGraphicsItem::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setMotionBuffer(); break;
        }
        _id -= 1;
    }
    return _id;
}

Verfasst: 4. März 2007 19:18
von Christian81
Leute lest die DOKU!
Wie kann man etwas benutzen wenn man nicht bereit ist auch mal was durchzulesen?
http://doc.trolltech.com/4.2/moc.html#m ... o-be-first

Verfasst: 4. März 2007 19:25
von upsala
Ganz einfach, er hat die Doku zu QObject nicht gelesen und QObject an der falschen Stelle 'positioniert'...

Edit: Ok, war zu langsam...

Verfasst: 4. März 2007 19:29
von slash-ex
ich habe ja die moc per hand angepasst :cry: ich habe auch verstanden warum er meckert... aber die moc wird ja automatisch bei mir falsch erzeugt!


so müsste sie aussehen!

Code: Alles auswählen

/****************************************************************************
** Meta object code from reading C++ file 'QUnit.h'
**
** Created: Sun Mar 4 19:23:44 2007
**      by: The Qt Meta Object Compiler version 59 (Qt 4.2.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include "battlefield/QUnit.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'QUnit.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 59
#error "This file was generated using the moc from 4.2.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

static const uint qt_meta_data_QUnit[] = {

 // content:
       1,       // revision
       0,       // classname
       0,    0, // classinfo
       1,   10, // methods
       0,    0, // properties
       0,    0, // enums/sets

 // slots: signature, parameters, type, tag, flags
       7,    6,    6,    6, 0x0a,

       0        // eod
};

static const char qt_meta_stringdata_QUnit[] = {
    "QUnit\0\0setMotionBuffer()\0"
};

const QMetaObject QUnit::staticMetaObject = {
    { &QObject::staticMetaObject, qt_meta_stringdata_QUnit,
      qt_meta_data_QUnit, 0 }
};

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

void *QUnit::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_QUnit))
	return static_cast<void*>(const_cast<QUnit*>(this));
    if (!strcmp(_clname, "QObject"))
	return static_cast<QObject*>(const_cast<QUnit*>(this));
    return QObject::qt_metacast(_clname);
}

int QUnit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setMotionBuffer(); break;
        }
        _id -= 1;
    }
    return _id;
}