qt receive msg from remote contral device in smart tv
-
Hi,
You should give more information:
- What smart TV ?
- How is the remote handling by the OS running on the device ?
- What OS is running on the device ?
- Version of Qt ?
etc.
-
Hi,
the tv remote contral device
http://www.easyicon.net/1188524-TV_Remote_icon.html
The remote contral device can contral the tv ui by the key 'up','down','ok','right','left'.I 'm not focus on the communication between the device with qt and the remote contral device,
but the qt's responses for the key 'up' from the remote contral device.
example:
qt can handle the 'up' key from the keyboard and ui responses ,then the focus moves up.
so, qt how handle the 'up' key from the remote contral device similarly? -
Do you realise that you are asking how Qt handles a device without giving any information about the actual device, how it is seen by the system and such vital information.
-
@SGaist
two steps:- the device with qt receive the info from the tv remote controller
2.qt handle and response the info
first have achieved.
the second is my focus and question.
now,I have a idea :
similar with virtual keyboard, qt uses the ```
sendEvent(QObject *receiver,QEvent *event)example :``` QKeyEvent upKey(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier); QCoreApplication::sendEvent(your_widget, &leftKey); ``
- the device with qt receive the info from the tv remote controller
-
@Alex_wang "the device with qt receive the info from the tv remote controller" - what does this mean? Does your device receive the event or are you already able to get the event in your Qt app? You should really explain better, else it is hard to understand what is working and what not.
-
my solution:
CKeyEvent.h
class CKeyEvent : public QObject { Q_OBJECT Q_ENUMS(CKEY_ID) public: enum CKEY_ID { CKEY_UP = Qt::Key_Up, CKEY_DOWN= Qt::Key_Down, CKEY_MAX }; CKeyEvent(QObject *parent = NULL); ~CKeyEvent(); Q_INVOKABLE void sendCkeyPressEvent(QObject* receiver,Qt::Key CkeyId); Q_INVOKABLE void sendCkeyReleaseEvent(QObject* receiver,Qt::Key CkeyId); private: QObject* m_receiver; };
CKeyEvent.cpp
CKeyEvent::CKeyEvent(QObject *parent):QObject(parent) { } CKeyEvent::~CKeyEvent() { } void CKeyEvent::sendCkeyPressEvent(QObject* receiver,Qt::Key CkeyId) { QKeyEvent keyPressEvent(QEvent::KeyPress, CkeyId, Qt::NoModifier); QGuiApplication::sendEvent(receiver, &keyPressEvent); } void CKeyEvent::sendCkeyReleaseEvent(QObject* receiver,Qt::Key CkeyId) { QKeyEvent keyReleaseEvent(QEvent::KeyRelease, CkeyId, Qt::NoModifier); QGuiApplication::sendEvent(receiver, &keyReleaseEvent); }
main.cpp
/int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; CKeyEvent *Ckey = new CKeyEvent(); engine.rootContext()->setContextProperty("cKeyCDP",Ckey); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
QML:main.qml
Window { id : mainWindows visible: true width: 1024 height: 768 title: qsTr("Hello World") KeyFocus { id : keyFocus; } Button { id :keyUp anchors.top:keyFocus.top anchors.topMargin: 20 anchors.left : keyFocus.right anchors.leftMargin: 20 width: 100 height: 60 text: qsTr("up") onClicked: { cKeyCDP.sendCkeyPressEvent(mainWindows,Qt.Key_Up); cKeyCDP.sendCkeyReleaseEvent(mainWindows,Qt.Key_Up); } } Button { id :keyDown anchors.top:keyUp.bottom anchors.topMargin: 20 anchors.left : keyFocus.right anchors.leftMargin: 20 width: 100 height: 60 text: qsTr("down") onClicked: { cKeyCDP.sendCkeyPressEvent(mainWindows,Qt.Key_Down); cKeyCDP.sendCkeyReleaseEvent(mainWindows,Qt.Key_Down); } } }