[Interest] QGuiApplication::focusObject not working in Qt 5.5.0

Nate Rogers bob119er at yahoo.com
Thu Apr 28 17:07:06 CEST 2016


I just upgraded to Qt 5.5.0 from Qt 5.3.2 and now my key presses are not working.  I am using QGuiApplication::focusObject to get the current object to send key press events to for a 5-way button I use on my embedded system to duplicate the arrow keys on a keyboard.
Here is the code that sends the key press events
        // Yes, setup the key event information        QKeyEvent *event1 = new QKeyEvent(QKeyEvent::KeyPress, key, Qt::NoModifier, "", false);        QKeyEvent *event2 = new QKeyEvent(QKeyEvent::KeyRelease, key, Qt::NoModifier, "", false);
        // Get the gui item which currently has focus        QQuickItem *receiver = qobject_cast<QQuickItem *>(QGuiApplication::focusObject());
        qDebug() << "receiver: " << receiver;
        // Is there an item in the gui that has focus?        if (receiver && !m_TestController->isButtonTestActive())        {            // Yes, send the key press and release events to it to simulate a key press            receiver->window()->sendEvent(receiver, &event1);            receiver->window()->sendEvent(receiver, &event2);        }
code 

In Qt 5.3.2 my qDebug() print would read...
receiver:  QQuickImage (this = 0x3bb448 , name= "" , parent = 0x3bad10 , geometry = QRectF(0,0 110x40) , z = 0 )

OR
receiver:  MenuList_QMLTYPE_30 (this = 0x6856e8 , name= "" , parent = 0xa80958 , geometry = QRectF(0,39 430x188) , z = 0 )

However on Qt 5.5.0 my qDebug print always reads...
receiver:  PageStack_QMLTYPE_13(0x459958, parent=0x398d68, geometry=0,0 480x272)

It seems like to me QGuiApplication::focusObject is broken in Qt 5.5.0?  Or is there a new way to do this in Qt 5.5.0?
Thanks!
Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160428/c2f004eb/attachment.html>


More information about the Interest mailing list