PDA

View Full Version : Help Newbie Subclass QStringList



avanta27
8th September 2012, 02:33
My first post here!

I am a newbie to Qt and quite newbie to C++. What I am trying to do is to subclass QStringList, but I don't make it. This is what I have tried out so far:



class MyStringList : public QStringList
{
Q_OBJECT

public:
MyStringList();


protected:
int numbers_pos[100];

public Q_SLOTS:
void set_number(int pos, int line_number);
int get_number(int pos);
};


I'm getting errors that:


error: invalid static_cast from type 'QObject*' to type 'MyStringList*'

and I am quite sure that it has to do with the Q_OBJECT macro. However, it does not let me remove it.

Any guesses?

Thanks a lot !

wysota
8th September 2012, 04:53
QStringList is not a subclass of QObject. Its subclasses cannot have signals or slots unless you inherit them from QObject as well. However it is very unusual to subclass both QObject and QStringList. It's more likely you should subclass QObject and equip it with a QStringList property instead.