Home > Mobile > Qt how to send the send to the child window/post a custom event
Qt how to send the send to the child window/post a custom event
Time:09-21
Recently a GUI, you need to change the original eventfilters is installed in the mainwindow UI - & gt; BoardView listening about key, but I need to monitor the replacement for custom events (more than threshold value when a variable), but in the main. I need to manually send events in the CPP, but can only send to the mainwindow w, but not to the UI - & gt; BoardView, event monitor can monitor events, relevant code visible at https://stackoverflow.com/questions/60424216/how-to-use-eventfilter-under-child-widget-to-catch-self-define-event or on https://www.zhihu.com/question/375221137
CodePudding user response:
Then post
Void QCoreApplication: : postEvent (QObject * receiver, QEvent * event, int priority) The first parameter is the object of the receiver Modified to QCoreApplication: : postEvent (UI - & gt; BoardView,... ), the UI - & gt; BoardView window can receive events
CodePudding user response:
Problem is that the UI definition within the mainwindow, once I in the main. Repairing the CPP to QCoreApplication: : postEvent (UI - & gt; BoardView,... ), the compile time error UI: 2 of undeclared identifier, what method can solve?
CodePudding user response:
You estimate didn't really understand the event mechanism, an object to be able to receive and process the event first to inherit from QObject, secondly want to implement the event (), the third: the object to start the eventloop. Generally speaking, there are eventloop class basically all have so a function to start the eventloop: exec ()