Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. C++ to QML signal issue
Forum Updated to NodeBB v4.3 + New Features

C++ to QML signal issue

Scheduled Pinned Locked Moved Solved Language Bindings
5 Posts 3 Posters 1.5k 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.
  • H Offline
    H Offline
    Hoyt
    wrote on last edited by p3c0
    #1

    I am having issues accessing an intValueChanged signal. I apologize in advance for this newbie question.

    The class that defines the intValueChanged signal follows:

    class IntValue : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(qint16 intValue READ intValue WRITE setIntValue NOTIFY intValueChanged)
    
    public:
        void setIntValue(const qint16 &a)
        {
            if (a != v)
            {
                v = a;
                emit intValueChanged();
            }
        }
    
        qint16 intValue() const
        {
            return v;
        }
    
    signals:
        void intValueChanged();
    
    private:
        qint16 v;
    };
    

    My main.cpp file contains the following:

    IntValue rotationAngle;
    engine.rootContext()->setContextProperty("rotationAngle", &rotationAngle);
    

    In my QML file, I can set read and set rotationAngle.intValue. For example, I can read rotationAngle.intValue as shown below:

    angle: rotationAngle.intValue;
    

    How would I access the intValueChanged signal?

    Thank you in advance.

    Hoyt

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Hoyt
      You can use Connections and keep the target as rotationAngle. Now since you have signal named intValueChanged Qt automatically provides a signal handler named onIntValueChanged. Use this handler in your Connections.
      More info:
      http://doc.qt.io/qt-5/qtqml-syntax-signals.html#receiving-signals-with-signal-handlers

      157

      H 1 Reply Last reply
      4
      • shavS Offline
        shavS Offline
        shav
        wrote on last edited by
        #3

        Hi,

        I think you can use something like this:

        Component.onCompleted: {
            if(rotationAngle !== null && rotationAngle !== undefined) {
                rotationAngle.intValueChanged.connect(function (/* parameters from signal if needed */) {
                    //Dome code here
                });
            }
        }
        

        Hope this help.

        Mac OS and iOS Developer

        1 Reply Last reply
        0
        • p3c0P p3c0

          @Hoyt
          You can use Connections and keep the target as rotationAngle. Now since you have signal named intValueChanged Qt automatically provides a signal handler named onIntValueChanged. Use this handler in your Connections.
          More info:
          http://doc.qt.io/qt-5/qtqml-syntax-signals.html#receiving-signals-with-signal-handlers

          H Offline
          H Offline
          Hoyt
          wrote on last edited by
          #4

          @p3c0

          Thank you very much. Connections, configured as you stated, worked perfectly.

          If I wanted to receive the same signal with a C++ object, would I also use Connections? If so, would you mind explaining how to configure Connections?

          Thanks again.

          Hoyt

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @Hoyt You already have that signal in your IntValue class. So in case you are trying to access this signal from other C++ class you have the instantiated object here:

            IntValue rotationAngle;
            engine.rootContext()->setContextProperty("rotationAngle", &rotationAngle);
            

            Use this object and connect to its SIGNAL intValueChanged.

            157

            1 Reply Last reply
            2

            • Login

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