keyeventfilter place create object
-
Hi,
I use keyeventfilter to read code scanner. I have a little problem with my project architecture. Below it is my main.cpp:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); MyKeyEventFilter myKeyEventFilter; app.installEventFilter(&myKeyEventFilter); //QML qmlRegisterType< SystemController > ("MyController",1,0,"SystemController"); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }The
SystemControllerI used to exchange data beetwen my logic and QML.Is it possible use
installEventFilterinsideSystemControllerand events would be works on whole application ? Thanks this, the signal fromMyKeyEventFilterI would connect to slot in other object created inside System Controller. now is impossible, i am right ?I try liake below:
SystemController::SystemController(QObject *parent) : QObject{parent} { MyKeyEventFilter myKeyEventFilter; this->installEventFilter(&myKeyEventFilter); }and I removed form main.cpp, but in this way events doesn't work....
-
@SGaist The MyKeyEventFilter works all the time when app is turn.
I solved my problem by integrate QML with qt by:engine.rootContext()->setContextProperty("myobject", myobject); -
Hi,
What is the lifetime of MyKeyEventFilter in SystemController's constructor ?
-
@SGaist The MyKeyEventFilter works all the time when app is turn.
I solved my problem by integrate QML with qt by:engine.rootContext()->setContextProperty("myobject", myobject); -
@SGaist The MyKeyEventFilter works all the time when app is turn.
I solved my problem by integrate QML with qt by:engine.rootContext()->setContextProperty("myobject", myobject);@Damian7546 you may pay more attention to what SGaist said. Try to use more heap space(pointers), especially Qt items or classes.
this kind of definition MyKeyEventFilter myKeyEventFilter; can be fatal in your app sometimes.
Try to use pointer: auto myKeyEventFilter = new MyKeyEventFilter; -
@Damian7546 you may pay more attention to what SGaist said. Try to use more heap space(pointers), especially Qt items or classes.
this kind of definition MyKeyEventFilter myKeyEventFilter; can be fatal in your app sometimes.
Try to use pointer: auto myKeyEventFilter = new MyKeyEventFilter;@JoeCFD said in keyeventfilter place create object:
this kind of definition MyKeyEventFilter myKeyEventFilter; can be fatal in your app sometimes.
I would be really grateful if you could explain me why ?