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. How QML emit signal,C++ receive signal from QML ,,,
Forum Updated to NodeBB v4.3 + New Features

How QML emit signal,C++ receive signal from QML ,,,

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 24.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.
  • B Offline
    B Offline
    bonbinker
    wrote on last edited by
    #1

    such as
    int the *.qml
    @signal musicSeek(int x);
    MouseArea{
    //onPositionChanged: slider.x=mouse.x
    anchors.fill:parent
    drag.target: parent
    drag.minimumX: 2 ;drag.maximumX:400
    onClicked: {
    slider.x=mouse.x-32
    musicSeek(slider.x)
    }
    }@

    in the main.cpp
    @QObject rootObject=dynamic_cast<QObject>(view.rootObject());
    connect(rootObject,SIGNAL(musicSeek(int)),this,SLOT(lseek(int)));
    @
    but is debug,,the result is Object::connect: No such signal QDeclarativeRectangle::musicSeek(int) in ..\3Dqml\main.cpp
    it is dont't find signal...

    who know ,,please tell me ..God bless me

    [Edit: Please, don't forget @-tags /Vass]

    人生有多少年华
    人生有多少缅怀
    人生有多少不后悔
    我们沉沦,沉沦在茫茫的暮色
    沉沦在烦琐的人生

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      The following "wiki page":http://developer.qt.nokia.com/wiki/Connect_a_complex_signal_from_QML_to_Qt contains an example that shows how to connect a signal from QML to C++. Does it help solve your problem?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bonbinker
        wrote on last edited by
        #3

        [quote author="sigrid" date="1316422549"]The following "wiki page":http://developer.qt.nokia.com/wiki/Connect_a_complex_signal_from_QML_to_Qt contains an example that shows how to connect a signal from QML to C++. Does it help solve your problem?
        [/quote]thank you ,,the is single case ,,your case use QDEclarativeItem..
        QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(view.rootObject());

        my code is QObject rootObject=dynamic_cast<QObject>(view.rootObject());
        my class from QOBject inherit..
        in the Object::connect: No such signal QDeclarativeRectangle::musicSeek(int)
        QDeclarativeRectangle maybe is promblem key...

        thank you ....

        人生有多少年华
        人生有多少缅怀
        人生有多少不后悔
        我们沉沦,沉沦在茫茫的暮色
        沉沦在烦琐的人生

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sigrid
          wrote on last edited by
          #4

          It is hard to tell what's causing this problem without more information. Can you post a small, complete example that reproduces the issue you are having?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bonbinker
            wrote on last edited by
            #5

            thank you ,,I give up signal and slot connect modle...
            use
            @
            Q_INVOKABLE void lseek(qint64 temp);

            MouseArea{
            ****
            onReleased:Main.seekChanged();
            }

            function seekChanged(){
            var m=(slider.x)/hex*1000
            //console.log("the current m:")
            //console.log(m)
            music.lseek(m)
            }
            @
            this modle may run, then my brain is orderless
            haha ,,
            thank you very much.....

            [Edit: Code formatting. Please use @ tags; mlong]

            人生有多少年华
            人生有多少缅怀
            人生有多少不后悔
            我们沉沦,沉沦在茫茫的暮色
            沉沦在烦琐的人生

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TreNrod
              wrote on last edited by
              #6

              Hi,

              had a similar problem. Searched for the easiest approach.

              • No declariation inthe main.qml: signal insertNewItem(string dayId, string amount, string descr, string group)
              • No signal and slots connection: QObject::connect(item, SIGNAL(insertNewItem(...

              This is how it works in my example:

              The Button where the signal is triggered
              @
              Button {
              id:but_Add
              height: 50
              width: parent.width
              text: "Add"

                      MouseArea{
                          anchors.fill: parent
                          onClicked: {
                              //C++ class containing the slot
                              dataHandler.insertNewItem(dateKey, txtInAmount.text, txtInReason.text, txtInGroup.text)
                          }
                          onPressed: {
                              parent.color = "blue"
              
                          }
                          onReleased: {
                              parent.color = "white"
                          }
                      }
                  }
              

              @

              Just a slots declination in the DateHandler...
              @
              public slots:
              void insertNewItem(const QString &dayId, const QString &amount, const QString &descr, const QString &group);
              @

              .. which we send give the context Property as a "dateHandler" to use in QML
              @
              m_dataHandler = new DataHandler(this);
              m_context->setContextProperty("dataHandler", m_dataHandler);
              @
              Best regards

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luca
                wrote on last edited by
                #7

                You could try to remove ';' character in:
                @
                signal musicSeek(int x);
                @

                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