I am trying to extend QLine class to include a color attribute. I used QCreator to create the code for the new class QLineColor and I just added the attribute char color=0 in the public data. Here is the code generated by QCreator.
UPDATE: Modified according to response about QObject. but now I am getting some other errors:
/home/james/qtsdk-2010.05/qt/include/QtCore/qobject.h:309: error:
‘QObject::QObject(const QObject&)’ is private
within this context
and it lists several qt/include directories
File:QLineColor.h
#ifndef QLINECOLOR_H
#define QLINECOLOR_H
#include <QLine>
#include <QObject>
class QLineColor : public QObject, public QLine
{
Q_OBJECT
public:
explicit QLineColor(int x1, int y1, int x2, int y2, char color);
char color;
};
#endif // QLINECOLOR_H
File:qlinecolor.cpp
#include "qlinecolor.h"
QLineColor::QLineColor(int x1, int y1, int x2, int y2, char color) :
QLine(x1, y1, x2, y2)
{
color = 0;
}
QLine doesn’t derive from QObject. Therefore Q_OBJECT etc. are all undefined.
should work.