Not getting Key and mouse events.



  • Hi All,

    I am trying to build one sample application using QML+JavaScript and CPP.
    I an facing problem while running the application.

    My application does not receive any keyboard/key events also I am not getting proper mouse click events.
    I have one QML file in which i have two rectangles where I have key and mouse event listener code:

    @
    Rectangle
    {
    id: keyRect
    focus:true;
    color: "black"
    Keys.onPressed:
    {
    console.log("Keys.onPressed\n");
    }
    }

    Rectangle
    {
    id: mouseRect;
    focus:true;
    color: "blue"
    MouseArea
    {
    anchors.fill: parent
    acceptedButtons: Qt.LeftButton;
    onReleased:
    {
    console.log("Mouse Clicked\n");
    }
    }
    }
    @

    I am not getting any events in key listener "Keys.onPressed:" and for mouse event whenever I move mouse pointer on the mouse rectangle (without clicking) I get print "Mouse Clicked" print.

    This is my main.cpp file from where i am launching the first qml file which will start the application.

    @#include <QApplication>
    #include <QtDeclarative>
    #include <QDeclarativeView>
    #include <QVariant>

    QT_USE_NAMESPACE

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

    QDeclarativeView view;
    view.setSource(QUrl::fromLocalFile&#40;"appEntry.qml"&#41;);
    
    app.setApplicationName("TestApp");
    app.setOrganizationName("Test");
    app.setOrganizationDomain("TestApp.com");
    
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.show();
    
    app.exec();
    
    return 0;
    

    }
    @

    Do i need to add anything else in above code to make it work.
    When i run this QML file with QML viewer it is working perfectly I am getting all the events.

    Thanks in advance.



  • Hi,

    you can try the below line.

    Component.onCompleted:{ keyRect.focus = true }



  • Did you use sendEvent with keyEvent ?


Log in to reply
 

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