[Qt-qml] QML signal not firing c++ slot

Chandraprakash Sharma envy.cp at gmail.com
Mon Aug 2 14:43:40 CEST 2010


my qml file
----------------------------------------------------------------
import Qt 4.7
import "qml"
import "jscript.js" as CalcEngine
 Item {
     id:container
     width: 1024
     height: 768


     signal ttsrequired(string txt);
     function doOp(operation){CalcEngine.doOperation(operation)}

     Component.onCompleted: { pageLoader.source= "qml/Poke.qml";
container.ttsrequired("Hello"); console.log("event sent")}
     Image {
         source:"pics/robot_IR.jpg"
         id: background
         fillMode: Image.TileHorizontally
         width: Math.max(pageLoader.width, parent.width)
     }

     Loader { id: pageLoader
         anchors.horizontalCenter:parent.horizontalCenter
         anchors.verticalCenter:parent.verticalCenter
         anchors.verticalCenterOffset: children[0].voff

     }

     Loader { id: pageLoaderin
         source: pageLoader.children[0].src
        anchors.horizontalCenter:parent.horizontalCenter
        y:350
    }

     Slider{
         anchors.bottom: parent.bottom
     }

     Button {x:930; y:0; width: 100; height: 100; keyc: "quit";}

     //onTtsrequired: console.log(txt + " QML");
 }

slot in c++ code
--------------------------------------------------------------
public slots: void sayText(QString txt){
        qDebug("Hello Debug");
        QMessageBox msgBox;
        msgBox.setText(txt);
        msgBox.exec();
}

Main.cpp file

#include <QApplication>
#include <QGraphicsObject>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <TTSAdaptor.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    TTSAdaptor ttsAdaptor;
    QDeclarativeView view;

view.setSource(QUrl::fromLocalFile("/home/saurabh/qtcreator-2.0.80/bin/TestNeel/start.qml"));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

    //view.showFullScreen();

    QDeclarativeContext *context = view.rootContext();
    context->setContextProperty("backgroundColor",
                                QColor("#ffffff"));

    QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());
    QObject::connect(rootObject, SIGNAL(ttsrequired(QString)), &ttsAdaptor,
SLOT(sayText(QString)));
    QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &app,
SLOT(quit()));

    view.show();
    return app.exec();
}

signal ttsrequired is being fired in qml locally but c++ slot is not
responding. I have tried many ways but not of help. Please revert if some
problem is detected!

Regards,
Chandraprakash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100802/7e24f1b5/attachment.html 


More information about the Qt-qml mailing list