Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can C++ signal be called from QML
Forum Updated to NodeBB v4.3 + New Features

Can C++ signal be called from QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 377 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.
  • V Offline
    V Offline
    Vinoth Rajendran4
    wrote on last edited by Vinoth Rajendran4
    #1
    class Hello : public QObject
    {
        Q_OBJECT
    
    signals:
        void sampleSignal();
    };
    
    // main.cpp
    Hello obj;
    engine.rootContext()->setContextProperty("Hello", (*QObject) (&obj));
    
    // QML
    MouseArea {
        anchors.fill: parent
        onClicked: {
           Hello.sampleSignal()
        }
    }
    

    I tried calling c++ signal from QML. Seems to be working fine. But i could not find any documentation for it.
    So i just need to know, if this is valid ?

    sierdzioS 1 Reply Last reply
    0
    • V Vinoth Rajendran4

      @sierdzio : Thanks .. But i could not find any documentation regarding this. Can you please direct me to the documentation link if any available ?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #4

      @Vinoth-Rajendran4 said in Can C++ signal be called from QML:

      Can you please direct me to the documentation link if any available ?

      Take a look at this: https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-signals

      Any public signal of a QObject-derived type is accessible from QML code.

      The QML engine automatically creates a signal handler for any signal of a QObject-derived type that is used from QML. Signal handlers are always named on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. All parameters passed by the signal are available in the signal handler through the parameter names.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      4
      • V Vinoth Rajendran4
        class Hello : public QObject
        {
            Q_OBJECT
        
        signals:
            void sampleSignal();
        };
        
        // main.cpp
        Hello obj;
        engine.rootContext()->setContextProperty("Hello", (*QObject) (&obj));
        
        // QML
        MouseArea {
            anchors.fill: parent
            onClicked: {
               Hello.sampleSignal()
            }
        }
        

        I tried calling c++ signal from QML. Seems to be working fine. But i could not find any documentation for it.
        So i just need to know, if this is valid ?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @Vinoth-Rajendran4 said in Can C++ signal be called from QML:

        So i just need to know, if this is valid ?

        Yes.

        (Z(:^

        V 1 Reply Last reply
        3
        • sierdzioS sierdzio

          @Vinoth-Rajendran4 said in Can C++ signal be called from QML:

          So i just need to know, if this is valid ?

          Yes.

          V Offline
          V Offline
          Vinoth Rajendran4
          wrote on last edited by Vinoth Rajendran4
          #3

          @sierdzio : Thanks .. But i could not find any documentation regarding this. Can you please direct me to the documentation link if any available ?

          KroMignonK 1 Reply Last reply
          0
          • V Vinoth Rajendran4

            @sierdzio : Thanks .. But i could not find any documentation regarding this. Can you please direct me to the documentation link if any available ?

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by KroMignon
            #4

            @Vinoth-Rajendran4 said in Can C++ signal be called from QML:

            Can you please direct me to the documentation link if any available ?

            Take a look at this: https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-signals

            Any public signal of a QObject-derived type is accessible from QML code.

            The QML engine automatically creates a signal handler for any signal of a QObject-derived type that is used from QML. Signal handlers are always named on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. All parameters passed by the signal are available in the signal handler through the parameter names.

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            4

            • Login

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