Results 1 to 2 of 2

Thread: Help Newbie Subclass QStringList

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Help Newbie Subclass QStringList

    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:

    Qt Code:
    1. class MyStringList : public QStringList
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyStringList();
    7.  
    8.  
    9. protected:
    10. int numbers_pos[100];
    11.  
    12. public Q_SLOTS:
    13. void set_number(int pos, int line_number);
    14. int get_number(int pos);
    15. };
    To copy to clipboard, switch view to plain text mode 

    I'm getting errors that:
    Qt Code:
    1. error: invalid static_cast from type 'QObject*' to type 'MyStringList*'
    To copy to clipboard, switch view to plain text mode 
    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 !

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help Newbie Subclass QStringList

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Help QStringList
    By pcoliver in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2011, 10:15
  2. Plz help me,I met a bug about QStringList
    By study_c in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2010, 15:56
  3. Replies: 8
    Last Post: 12th February 2010, 02:41
  4. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.