PDA

View Full Version : Problems subclassing QListWidgetItem



Morea
7th May 2006, 22:03
I'm trying to derive a class from QListWidgetItem, but I get some problem with it.
Here is compile error:


g++ -c -pipe -O2 -march=athlon-xp -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/doc/qt-4.1.1/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o moc_pkt.o moc_pkt.cpp
moc_pkt.cpp:37: error: `staticMetaObject' is not a member of type `
QListWidgetItem'
moc_pkt.cpp: In member function `virtual void* Point::qt_metacast(const char*)
':
moc_pkt.cpp:51: error: 'class QListWidgetItem' has no member named 'qt_metacast
'
moc_pkt.cpp: In member function `virtual int
Point::qt_metacall(QMetaObject::Call, int, void**)':
moc_pkt.cpp:56: error: 'class QListWidgetItem' has no member named 'qt_metacall
'
make: *** [moc_pkt.o] Error 1



and here is code

#ifndef pkt_h
#define pkt_h
#include <QtCore>
#include <QtGui>

class Point:public QListWidgetItem {
Q_OBJECT
public:
Point(){} // DO NOT USE
Point(QPoint _p, QString _label, QListWidget* parent);
public slots:
private:
protected:
QPoint p;
QPoint relLabelPos; // relative position of label to point
QString label; // label of the point
};

#endif



#include <QtCore>
#include <QtGui>
#include "pkt.h"


Point::Point(QPoint _p, QString _label, QListWidget* parent)
:QListWidgetItem(parent)
{
p = _p;
label = _label;
setText(label);
}


Any ideas?

Morea
7th May 2006, 22:21
The problem went away when I removed Q_OBJECT from the code.

wysota
8th May 2006, 09:27
Q_OBJECT provides some additional functionality for objects -- like signals, slots, etc. But it also requires that the class inherits QObject, which was missing in your case. But if you don't need signals/slots or meta-data, you don't need the Q_OBJECT macro.