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



  • 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]



  • 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 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 ....



  • 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?



  • 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]



  • 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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.