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. Issues When Add the Q_OBJECT to My SubClass of QGraphicsRectItem
Forum Updated to NodeBB v4.3 + New Features

Issues When Add the Q_OBJECT to My SubClass of QGraphicsRectItem

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 5.1k Views 1 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.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by joeQ
    #1

    like the head file, i had the subclass of QGraphicsRectItem.

    #ifndef GRAPHICSRECTITEM_H
    #define GRAPHICSRECTITEM_H
    
    #include <QGraphicsRectItem>
    
    class GraphicsRectItem : public QGraphicsRectItem
    {
    public:
        explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR);
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    
    protected:
        /**...*/
    
    private:
    
        /**...*/
    private:
    
        /**...*/
    };
    
    #endif // GRAPHICSRECTITEM_H
    

    Every thing was ok. Where was no Q_OBJECT

    But, i want to use the signal and slot. so, i add the Q_OBJECT. like below.

    class GraphicsRectItem : public QGraphicsRectItem
    {
        Q_OBJECT
    public:
        explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR);
        /**...*/
       
    

    Then, Has the some issues.

    1. ...error: 'staticMetaObject' is not a member of 'QGraphicsRectItem'...
    2. ...&QGraphicsRectItem::staticMetaObject, qt_meta_stringdata_GraphicsRectItem.data,...
    3. ...error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected QScopedPointer<QObjectData> d_ptr;
    4. ...error: within this context return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      ...

    I just want to use the signal and slot. so Add the Q_OBJECT in my class. But There has some wrong!

    I didn't understand Q_OBJECT well.

    Thank u.

    Just do it!

    J.HilkJ 1 Reply Last reply
    0
    • joeQJ joeQ

      like the head file, i had the subclass of QGraphicsRectItem.

      #ifndef GRAPHICSRECTITEM_H
      #define GRAPHICSRECTITEM_H
      
      #include <QGraphicsRectItem>
      
      class GraphicsRectItem : public QGraphicsRectItem
      {
      public:
          explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR);
          void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
      
      protected:
          /**...*/
      
      private:
      
          /**...*/
      private:
      
          /**...*/
      };
      
      #endif // GRAPHICSRECTITEM_H
      

      Every thing was ok. Where was no Q_OBJECT

      But, i want to use the signal and slot. so, i add the Q_OBJECT. like below.

      class GraphicsRectItem : public QGraphicsRectItem
      {
          Q_OBJECT
      public:
          explicit GraphicsRectItem(const QRect &rect,QGraphicsItem *parent = Q_NULLPTR);
          /**...*/
         
      

      Then, Has the some issues.

      1. ...error: 'staticMetaObject' is not a member of 'QGraphicsRectItem'...
      2. ...&QGraphicsRectItem::staticMetaObject, qt_meta_stringdata_GraphicsRectItem.data,...
      3. ...error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected QScopedPointer<QObjectData> d_ptr;
      4. ...error: within this context return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
        ...

      I just want to use the signal and slot. so Add the Q_OBJECT in my class. But There has some wrong!

      I didn't understand Q_OBJECT well.

      Thank u.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @joeQ said in Issues When Add the Q_OBJECT to My SubClass:

      Q_OBJECT

      Hi, I would recomment you taking some time and reading throught the docu.

      I'm not sure if QGraphicsRectItem actually subclasses of QObject but adding a #include <QObject> might help :)


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      joeQJ 1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        QGraphicsRectItem is not from QObject. You can't do this. Why do you want add Q_OBJECT ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        joeQJ 1 Reply Last reply
        2
        • J.HilkJ J.Hilk

          @joeQ said in Issues When Add the Q_OBJECT to My SubClass:

          Q_OBJECT

          Hi, I would recomment you taking some time and reading throught the docu.

          I'm not sure if QGraphicsRectItem actually subclasses of QObject but adding a #include <QObject> might help :)

          joeQJ Offline
          joeQJ Offline
          joeQ
          wrote on last edited by
          #4

          @J.Hilk

          I add the #include<QObject>. it didn't work.

          In the doc waht you said. I searched the QGraphicsRectItem or QGraphicsItem . and want to know that did them Inherited the QObject.
          They didn't inherited QObject.

          Just do it!

          1 Reply Last reply
          0
          • dheerendraD dheerendra

            QGraphicsRectItem is not from QObject. You can't do this. Why do you want add Q_OBJECT ?

            joeQJ Offline
            joeQJ Offline
            joeQ
            wrote on last edited by
            #5

            @dheerendra

            I want to use the signal and slot. I want to emit signal to scene(or to another rect item) when rect item size changed.

            Just do it!

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Then do something like this. It should work. Inherit from QObject.

              class MyItem : public QObject,public QGraphicsRectItem
              {
              Q_OBJECT
              public:
              MyItem();
              };

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              joeQJ 1 Reply Last reply
              5
              • dheerendraD dheerendra

                Then do something like this. It should work. Inherit from QObject.

                class MyItem : public QObject,public QGraphicsRectItem
                {
                Q_OBJECT
                public:
                MyItem();
                };

                joeQJ Offline
                joeQJ Offline
                joeQ
                wrote on last edited by
                #7

                @dheerendra

                Yes, (0o0), it's ok! Thank u. Very much. Excellent.

                Just do it!

                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