Results 1 to 3 of 3

Thread: Problems subclassing QListWidgetItem

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problems subclassing QListWidgetItem

    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 Pointublic 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?

  2. #2
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems subclassing QListWidgetItem

    The problem went away when I removed Q_OBJECT from the code.

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

    Default Re: Problems subclassing QListWidgetItem

    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.

  4. The following user says thank you to wysota for this useful post:

    Phlucious (18th June 2013)

Similar Threads

  1. Check Box problem
    By Seema Rao in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2007, 19:32
  2. Problems with Q_OBJECT and subclassing
    By renaissanz in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 22:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.