[Solved] How correctly inherit from QGraphicsPixmapItem?

  • Compiler show error:
    C:\Qt\Examples\Qt-5.3\widgets\widgets\imageviewer\debug\moc_imageitem.cpp:71: ошибка: invalid static_cast from type 'QObject*' to type 'ImageItem*'
    ImageItem *_t = static_cast<ImageItem *>(_o);

    What I do wrong?

    @#ifndef IMAGEITEM_H
    #define IMAGEITEM_H

    #include <QGraphicsPixmapItem>

    class ImageItem : public QGraphicsPixmapItem
    ImageItem(QPixmap pixmap) : QGraphicsPixmapItem(pixmap){}

    public slots:
    void changeVisibility(int state){
    if(state == 0)hide();
    else show();
    void changeOpacity(int level){

    #endif // IMAGEITEM_H@

  • QGraphicsPixmapItem does not inherit QObject so macro Q_OBJECT is incorrect here. If you need it to be QObject too then you need to inherit QObject explicitly.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.