Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "not list it in Q_INTERFACES" Warning ?
Forum Updated to NodeBB v4.3 + New Features

"not list it in Q_INTERFACES" Warning ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by
    #1

    What is the problem here and how can I fix it ?
    If more code necessary, please let me know, thank you.

    /Projects/Cella_02/mycellitem.h:18: Warning: Class MyCellItem implements the interface QGraphicsItem but does not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
    
    #ifndef MYCELLITEM_H
    #define MYCELLITEM_H
    
    #include <QGraphicsItem>
    #include <QPainter>
    
    class MyCellItem : public QObject, public QGraphicsItem
    {
        Q_OBJECT
    
    public:
        MyCellItem();
        ~MyCellItem();
    
        QRectF boundingRect() const;
    
        void paint(QPainter* painter, const QStyleOptionGraphicsItem *, QWidget *);
    };
    
    #endif // MYCELLITEM_H
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      deleted28
      wrote on last edited by
      #2

      OK, fixed it, but still do not understand, why this is necessary and what for.

      class MyCellItem : public QObject, public QGraphicsItem
      {
          Q_OBJECT
          Q_INTERFACES(QGraphicsItem)
      
      public:
      ...
      
      1 Reply Last reply
      0
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        It's needed for multitude of things, one of which is to provide RTTI when such is disabled for the compiler. You should refer to the docs for a full explanation on the macro. Also you're better off deriving from QGraphicsObject instead of the way you're doing it now.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • D Offline
          D Offline
          deleted28
          wrote on last edited by
          #4

          thanks for reply!

          this way ?

          class MyCellItem : public QGraphicsObject //, public QGraphicsItem
          {
              Q_OBJECT
          //    Q_INTERFACES(QGraphicsItem)
          
          
          public:
          

          ps. how to mark this thread as SOLVED ?

          kshegunovK 1 Reply Last reply
          0
          • D deleted28

            thanks for reply!

            this way ?

            class MyCellItem : public QGraphicsObject //, public QGraphicsItem
            {
                Q_OBJECT
            //    Q_INTERFACES(QGraphicsItem)
            
            
            public:
            

            ps. how to mark this thread as SOLVED ?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @wally123 said in "not list it in Q_INTERFACES" Warning ?:

            this way ?

            Yes. That's what I meant.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved