Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. When exactly to use a Q_PROPERTY ???
Forum Updated to NodeBB v4.3 + New Features

When exactly to use a Q_PROPERTY ???

Scheduled Pinned Locked Moved Unsolved Qt 6
8 Posts 4 Posters 1.2k 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.
  • Ash VA Offline
    Ash VA Offline
    Ash V
    wrote on last edited by
    #1

    @JonB , @Axel-Spoerl
    Hello !

    Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?
    Please refer to the below example.

    firstselfcodedqobjectclass.h

    #ifndef FIRSTSELFCODEDQOBJECTCLASS_H
    #define FIRSTSELFCODEDQOBJECTCLASS_H 
    
    #include <QObject>
    
    class FirstSelfCodedQObjectClass : public QObject
    {
        Q_OBJECT
    
    public:
        FirstSelfCodedQObjectClass(QObject *parent = nullptr);
        QString getName1() const;
        void setName1(const QString &name1);
    
    signals:
        void name1Changed(const QString& name1);
    
    private:
        QString m_name1;
    };
    
    #endif // FIRSTSELFCODEDQOBJECTCLASS_H
    

    firstselfcodedqobjectclass.cpp

    #include "firstselfcodedqobjectclass.h"
    
    FirstSelfCodedQObjectClass::FirstSelfCodedQObjectClass(QObject *parent)
        : QObject(parent)
    {}
    
    QString FirstSelfCodedQObjectClass::getName1() const
    {
        return m_name1;
    }
    
    void FirstSelfCodedQObjectClass::setName1(const QString &name1)
    {
        if(m_name1 != name1)
        {
            m_name1 = name1;
            emit name1Changed(m_name1);
        }
    }
    

    secondselfcodedqobjectclass.h

    #ifndef SECONDSELFCODEDQOBJECTCLASS_H
    #define SECONDSELFCODEDQOBJECTCLASS_H
    
    #include <QObject>
    #include "firstselfcodedqobjectclass.h"
    
    class FirstSelfCodedQObjectClass;
    class SecondSelfCodedQObjectClass : public QObject
    {
        Q_OBJECT
    
    public:
        SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
        QString getName2() const;
        void setName2(const QString &name2);
    
    public slots:
        void onName1Changed(const QString &name1);
    
    private:
        QString m_name2;
    };
    
    #endif // SECONDSELFCODEDQOBJECTCLASS_H
    

    secondselfcodedqobjectclass.cpp

    #include "secondselfcodedqobjectclass.h"
    
    SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
        : QObject(parent)
    {
        QObject::connect(fs
                       , &FirstSelfCodedQObjectClass::name1Changed
                       , this
                       , &SecondSelfCodedQObjectClass::onName1Changed);
    }
    
    QString SecondSelfCodedQObjectClass::getName2() const
    {
        return m_name2;
    }
    
    void SecondSelfCodedQObjectClass::setName2(const QString &name2)
    {
        if(m_name2 != name2)
        {
            m_name2 = name2;
        }
    }
    
    void SecondSelfCodedQObjectClass::onName1Changed(const QString &name1)
    {
        if(m_name2 != name1)
        {
            m_name2 = name1;
        }
    }
    

    main.cpp

    #include <QCoreApplication>
    #include <QDebug>
    
    #include "firstselfcodedqobjectclass.h"
    #include "secondselfcodedqobjectclass.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
        SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass(f);
    
        f->setName1("Justin Bieber");
        qDebug() << (f->getName1()); // Output Justin Bieber
        qDebug() << (s->getName2()); // Output Justin Bieber
    
        s->setName2("Julius Ceaser");
        qDebug() << (f->getName1()); // Output Justin Bieber
        qDebug() << (s->getName2()); // Output Julius Ceaser
    
        return a.exec();
    }
    

    I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above example that we can use it without necessarily having any Q_PROPERTY.

    This is the documentation I have referred to.

    I'd greatly appreciate your help on this topic....

    JonBJ Axel SpoerlA 3 Replies Last reply
    0
    • Ash VA Ash V

      @JonB , @Axel-Spoerl
      Hello !

      Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?
      Please refer to the below example.

      firstselfcodedqobjectclass.h

      #ifndef FIRSTSELFCODEDQOBJECTCLASS_H
      #define FIRSTSELFCODEDQOBJECTCLASS_H 
      
      #include <QObject>
      
      class FirstSelfCodedQObjectClass : public QObject
      {
          Q_OBJECT
      
      public:
          FirstSelfCodedQObjectClass(QObject *parent = nullptr);
          QString getName1() const;
          void setName1(const QString &name1);
      
      signals:
          void name1Changed(const QString& name1);
      
      private:
          QString m_name1;
      };
      
      #endif // FIRSTSELFCODEDQOBJECTCLASS_H
      

      firstselfcodedqobjectclass.cpp

      #include "firstselfcodedqobjectclass.h"
      
      FirstSelfCodedQObjectClass::FirstSelfCodedQObjectClass(QObject *parent)
          : QObject(parent)
      {}
      
      QString FirstSelfCodedQObjectClass::getName1() const
      {
          return m_name1;
      }
      
      void FirstSelfCodedQObjectClass::setName1(const QString &name1)
      {
          if(m_name1 != name1)
          {
              m_name1 = name1;
              emit name1Changed(m_name1);
          }
      }
      

      secondselfcodedqobjectclass.h

      #ifndef SECONDSELFCODEDQOBJECTCLASS_H
      #define SECONDSELFCODEDQOBJECTCLASS_H
      
      #include <QObject>
      #include "firstselfcodedqobjectclass.h"
      
      class FirstSelfCodedQObjectClass;
      class SecondSelfCodedQObjectClass : public QObject
      {
          Q_OBJECT
      
      public:
          SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
          QString getName2() const;
          void setName2(const QString &name2);
      
      public slots:
          void onName1Changed(const QString &name1);
      
      private:
          QString m_name2;
      };
      
      #endif // SECONDSELFCODEDQOBJECTCLASS_H
      

      secondselfcodedqobjectclass.cpp

      #include "secondselfcodedqobjectclass.h"
      
      SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
          : QObject(parent)
      {
          QObject::connect(fs
                         , &FirstSelfCodedQObjectClass::name1Changed
                         , this
                         , &SecondSelfCodedQObjectClass::onName1Changed);
      }
      
      QString SecondSelfCodedQObjectClass::getName2() const
      {
          return m_name2;
      }
      
      void SecondSelfCodedQObjectClass::setName2(const QString &name2)
      {
          if(m_name2 != name2)
          {
              m_name2 = name2;
          }
      }
      
      void SecondSelfCodedQObjectClass::onName1Changed(const QString &name1)
      {
          if(m_name2 != name1)
          {
              m_name2 = name1;
          }
      }
      

      main.cpp

      #include <QCoreApplication>
      #include <QDebug>
      
      #include "firstselfcodedqobjectclass.h"
      #include "secondselfcodedqobjectclass.h"
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
          SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass(f);
      
          f->setName1("Justin Bieber");
          qDebug() << (f->getName1()); // Output Justin Bieber
          qDebug() << (s->getName2()); // Output Justin Bieber
      
          s->setName2("Julius Ceaser");
          qDebug() << (f->getName1()); // Output Justin Bieber
          qDebug() << (s->getName2()); // Output Julius Ceaser
      
          return a.exec();
      }
      

      I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above example that we can use it without necessarily having any Q_PROPERTY.

      This is the documentation I have referred to.

      I'd greatly appreciate your help on this topic....

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Ash-V Answered at https://forum.qt.io/topic/154984/expected-primary-expression-before-token/4.

      1 Reply Last reply
      0
      • Ash VA Ash V

        @JonB , @Axel-Spoerl
        Hello !

        Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?
        Please refer to the below example.

        firstselfcodedqobjectclass.h

        #ifndef FIRSTSELFCODEDQOBJECTCLASS_H
        #define FIRSTSELFCODEDQOBJECTCLASS_H 
        
        #include <QObject>
        
        class FirstSelfCodedQObjectClass : public QObject
        {
            Q_OBJECT
        
        public:
            FirstSelfCodedQObjectClass(QObject *parent = nullptr);
            QString getName1() const;
            void setName1(const QString &name1);
        
        signals:
            void name1Changed(const QString& name1);
        
        private:
            QString m_name1;
        };
        
        #endif // FIRSTSELFCODEDQOBJECTCLASS_H
        

        firstselfcodedqobjectclass.cpp

        #include "firstselfcodedqobjectclass.h"
        
        FirstSelfCodedQObjectClass::FirstSelfCodedQObjectClass(QObject *parent)
            : QObject(parent)
        {}
        
        QString FirstSelfCodedQObjectClass::getName1() const
        {
            return m_name1;
        }
        
        void FirstSelfCodedQObjectClass::setName1(const QString &name1)
        {
            if(m_name1 != name1)
            {
                m_name1 = name1;
                emit name1Changed(m_name1);
            }
        }
        

        secondselfcodedqobjectclass.h

        #ifndef SECONDSELFCODEDQOBJECTCLASS_H
        #define SECONDSELFCODEDQOBJECTCLASS_H
        
        #include <QObject>
        #include "firstselfcodedqobjectclass.h"
        
        class FirstSelfCodedQObjectClass;
        class SecondSelfCodedQObjectClass : public QObject
        {
            Q_OBJECT
        
        public:
            SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
            QString getName2() const;
            void setName2(const QString &name2);
        
        public slots:
            void onName1Changed(const QString &name1);
        
        private:
            QString m_name2;
        };
        
        #endif // SECONDSELFCODEDQOBJECTCLASS_H
        

        secondselfcodedqobjectclass.cpp

        #include "secondselfcodedqobjectclass.h"
        
        SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
            : QObject(parent)
        {
            QObject::connect(fs
                           , &FirstSelfCodedQObjectClass::name1Changed
                           , this
                           , &SecondSelfCodedQObjectClass::onName1Changed);
        }
        
        QString SecondSelfCodedQObjectClass::getName2() const
        {
            return m_name2;
        }
        
        void SecondSelfCodedQObjectClass::setName2(const QString &name2)
        {
            if(m_name2 != name2)
            {
                m_name2 = name2;
            }
        }
        
        void SecondSelfCodedQObjectClass::onName1Changed(const QString &name1)
        {
            if(m_name2 != name1)
            {
                m_name2 = name1;
            }
        }
        

        main.cpp

        #include <QCoreApplication>
        #include <QDebug>
        
        #include "firstselfcodedqobjectclass.h"
        #include "secondselfcodedqobjectclass.h"
        
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
        
            FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
            SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass(f);
        
            f->setName1("Justin Bieber");
            qDebug() << (f->getName1()); // Output Justin Bieber
            qDebug() << (s->getName2()); // Output Justin Bieber
        
            s->setName2("Julius Ceaser");
            qDebug() << (f->getName1()); // Output Justin Bieber
            qDebug() << (s->getName2()); // Output Julius Ceaser
        
            return a.exec();
        }
        

        I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above example that we can use it without necessarily having any Q_PROPERTY.

        This is the documentation I have referred to.

        I'd greatly appreciate your help on this topic....

        Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #3

        @Ash-V
        Within Qt, we use the property system mainly for QML exposure.

        If you want to access a variable (e.g. with int MyClass::myNumber() constand void MyClass::setMyNumber(int number), you need to know these accessors at compile time. That means, whoever wants to see myNumber()or change it, needs to include the headers of MyClass.

        The Q_PROPERTY macro makes accessors to a variable available at runtime. A caller only needs to know that MyClassinherits from QObject. It can use QMetaObject to find property names and e.g. use QObject::setProperty("myNumber", 42); to modify it.

        Software Engineer
        The Qt Company, Oslo

        Ash VA 2 Replies Last reply
        2
        • Axel SpoerlA Axel Spoerl

          @Ash-V
          Within Qt, we use the property system mainly for QML exposure.

          If you want to access a variable (e.g. with int MyClass::myNumber() constand void MyClass::setMyNumber(int number), you need to know these accessors at compile time. That means, whoever wants to see myNumber()or change it, needs to include the headers of MyClass.

          The Q_PROPERTY macro makes accessors to a variable available at runtime. A caller only needs to know that MyClassinherits from QObject. It can use QMetaObject to find property names and e.g. use QObject::setProperty("myNumber", 42); to modify it.

          Ash VA Offline
          Ash VA Offline
          Ash V
          wrote on last edited by
          #4

          @JonB , @Axel-Spoerl
          Thanks, Axel, as well as Jon !

          I want to thank you both for being helpful !

          1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            @Ash-V
            Within Qt, we use the property system mainly for QML exposure.

            If you want to access a variable (e.g. with int MyClass::myNumber() constand void MyClass::setMyNumber(int number), you need to know these accessors at compile time. That means, whoever wants to see myNumber()or change it, needs to include the headers of MyClass.

            The Q_PROPERTY macro makes accessors to a variable available at runtime. A caller only needs to know that MyClassinherits from QObject. It can use QMetaObject to find property names and e.g. use QObject::setProperty("myNumber", 42); to modify it.

            Ash VA Offline
            Ash VA Offline
            Ash V
            wrote on last edited by
            #5

            @Axel-Spoerl
            But Axel,
            as you mentioned here,

            c1a8072a-e727-4a4e-9486-ff43b1ecc7e2-image.png
            the Q_PROPERTY isn't useful in the C++ part of Qt, right ?

            Suppose I have a class class FirstClass : public QObject and a class SecondClass wherein I want to use the accessors of FirstClass.

            Now, both ways (with or without using Q_PROPERTY) I definitely need to import the firstclass.hpp header file, I guess.
            Because while referring the accessors of FirstClass, in SecondClass, I will refer them as FirstClass::<accessor>().

            Am I correct here Axel ???
            Or there's something I'm missing here — any enhancements I can gain even in the C++ side of Qt via the usage of Q_PROPERTY ?

            Christian EhrlicherC 1 Reply Last reply
            0
            • Ash VA Ash V

              @Axel-Spoerl
              But Axel,
              as you mentioned here,

              c1a8072a-e727-4a4e-9486-ff43b1ecc7e2-image.png
              the Q_PROPERTY isn't useful in the C++ part of Qt, right ?

              Suppose I have a class class FirstClass : public QObject and a class SecondClass wherein I want to use the accessors of FirstClass.

              Now, both ways (with or without using Q_PROPERTY) I definitely need to import the firstclass.hpp header file, I guess.
              Because while referring the accessors of FirstClass, in SecondClass, I will refer them as FirstClass::<accessor>().

              Am I correct here Axel ???
              Or there's something I'm missing here — any enhancements I can gain even in the C++ side of Qt via the usage of Q_PROPERTY ?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Ash-V said in When exactly to use a Q_PROPERTY ???:

              any enhancements I can gain even in the C++ side of Qt via the usage of Q_PROPERTY ?

              As already said there are none.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • Ash VA Ash V

                @JonB , @Axel-Spoerl
                Hello !

                Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?
                Please refer to the below example.

                firstselfcodedqobjectclass.h

                #ifndef FIRSTSELFCODEDQOBJECTCLASS_H
                #define FIRSTSELFCODEDQOBJECTCLASS_H 
                
                #include <QObject>
                
                class FirstSelfCodedQObjectClass : public QObject
                {
                    Q_OBJECT
                
                public:
                    FirstSelfCodedQObjectClass(QObject *parent = nullptr);
                    QString getName1() const;
                    void setName1(const QString &name1);
                
                signals:
                    void name1Changed(const QString& name1);
                
                private:
                    QString m_name1;
                };
                
                #endif // FIRSTSELFCODEDQOBJECTCLASS_H
                

                firstselfcodedqobjectclass.cpp

                #include "firstselfcodedqobjectclass.h"
                
                FirstSelfCodedQObjectClass::FirstSelfCodedQObjectClass(QObject *parent)
                    : QObject(parent)
                {}
                
                QString FirstSelfCodedQObjectClass::getName1() const
                {
                    return m_name1;
                }
                
                void FirstSelfCodedQObjectClass::setName1(const QString &name1)
                {
                    if(m_name1 != name1)
                    {
                        m_name1 = name1;
                        emit name1Changed(m_name1);
                    }
                }
                

                secondselfcodedqobjectclass.h

                #ifndef SECONDSELFCODEDQOBJECTCLASS_H
                #define SECONDSELFCODEDQOBJECTCLASS_H
                
                #include <QObject>
                #include "firstselfcodedqobjectclass.h"
                
                class FirstSelfCodedQObjectClass;
                class SecondSelfCodedQObjectClass : public QObject
                {
                    Q_OBJECT
                
                public:
                    SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
                    QString getName2() const;
                    void setName2(const QString &name2);
                
                public slots:
                    void onName1Changed(const QString &name1);
                
                private:
                    QString m_name2;
                };
                
                #endif // SECONDSELFCODEDQOBJECTCLASS_H
                

                secondselfcodedqobjectclass.cpp

                #include "secondselfcodedqobjectclass.h"
                
                SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
                    : QObject(parent)
                {
                    QObject::connect(fs
                                   , &FirstSelfCodedQObjectClass::name1Changed
                                   , this
                                   , &SecondSelfCodedQObjectClass::onName1Changed);
                }
                
                QString SecondSelfCodedQObjectClass::getName2() const
                {
                    return m_name2;
                }
                
                void SecondSelfCodedQObjectClass::setName2(const QString &name2)
                {
                    if(m_name2 != name2)
                    {
                        m_name2 = name2;
                    }
                }
                
                void SecondSelfCodedQObjectClass::onName1Changed(const QString &name1)
                {
                    if(m_name2 != name1)
                    {
                        m_name2 = name1;
                    }
                }
                

                main.cpp

                #include <QCoreApplication>
                #include <QDebug>
                
                #include "firstselfcodedqobjectclass.h"
                #include "secondselfcodedqobjectclass.h"
                
                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc, argv);
                
                    FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
                    SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass(f);
                
                    f->setName1("Justin Bieber");
                    qDebug() << (f->getName1()); // Output Justin Bieber
                    qDebug() << (s->getName2()); // Output Justin Bieber
                
                    s->setName2("Julius Ceaser");
                    qDebug() << (f->getName1()); // Output Justin Bieber
                    qDebug() << (s->getName2()); // Output Julius Ceaser
                
                    return a.exec();
                }
                

                I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above example that we can use it without necessarily having any Q_PROPERTY.

                This is the documentation I have referred to.

                I'd greatly appreciate your help on this topic....

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Ash-V
                You have:

                #include "firstselfcodedqobjectclass.h"
                
                class FirstSelfCodedQObjectClass;
                
                SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
                
                ...
                
                SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
                    : QObject(parent)
                {
                    QObject::connect(fs
                                   , &FirstSelfCodedQObjectClass::name1Changed
                                   , this
                                   , &SecondSelfCodedQObjectClass::onName1Changed);
                }
                

                While this works, it is probably not the most common pattern. It makes SecondSelfCodedQObjectClass have to know about FirstSelfCodedQObjectClass and require it.

                In your other thread I suggested at https://forum.qt.io/topic/154984/expected-primary-expression-before-token/2

                You are trying to do connections in constructor of SecondSetCodedObjectClass. This is usually not good, because you would have to pass an instance of signalling object to that constructor. Rather the usual place to do the connect() is (on the line after) where you call new SecondSetCodedObjectClass, which has visibility of that new slot object and the existing signal object (FirstSetCodedObjectClass *) which you want to connect.

                I would likely change your main() to:

                    FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
                    SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass;
                    QObject::connect(f
                                   , &FirstSelfCodedQObjectClass::name1Changed
                                   , s
                                   , &SecondSelfCodedQObjectClass::onName1Changed);
                

                You should at least be aware of this pattern and understand it, it is more common.

                Ash VA 1 Reply Last reply
                1
                • JonBJ JonB

                  @Ash-V
                  You have:

                  #include "firstselfcodedqobjectclass.h"
                  
                  class FirstSelfCodedQObjectClass;
                  
                  SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent = nullptr);
                  
                  ...
                  
                  SecondSelfCodedQObjectClass::SecondSelfCodedQObjectClass(FirstSelfCodedQObjectClass *fs, QObject *parent)
                      : QObject(parent)
                  {
                      QObject::connect(fs
                                     , &FirstSelfCodedQObjectClass::name1Changed
                                     , this
                                     , &SecondSelfCodedQObjectClass::onName1Changed);
                  }
                  

                  While this works, it is probably not the most common pattern. It makes SecondSelfCodedQObjectClass have to know about FirstSelfCodedQObjectClass and require it.

                  In your other thread I suggested at https://forum.qt.io/topic/154984/expected-primary-expression-before-token/2

                  You are trying to do connections in constructor of SecondSetCodedObjectClass. This is usually not good, because you would have to pass an instance of signalling object to that constructor. Rather the usual place to do the connect() is (on the line after) where you call new SecondSetCodedObjectClass, which has visibility of that new slot object and the existing signal object (FirstSetCodedObjectClass *) which you want to connect.

                  I would likely change your main() to:

                      FirstSelfCodedQObjectClass *f = new FirstSelfCodedQObjectClass;
                      SecondSelfCodedQObjectClass *s = new SecondSelfCodedQObjectClass;
                      QObject::connect(f
                                     , &FirstSelfCodedQObjectClass::name1Changed
                                     , s
                                     , &SecondSelfCodedQObjectClass::onName1Changed);
                  

                  You should at least be aware of this pattern and understand it, it is more common.

                  Ash VA Offline
                  Ash VA Offline
                  Ash V
                  wrote on last edited by
                  #8

                  @JonB
                  Thank you Jon !

                  Thanks for giving this additional valuable reply....

                  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