<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[keyeventfilter place create object]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I use keyeventfilter to read code scanner. I have a little  problem with my project architecture. Below it is my main.cpp:</p>
<pre><code>int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    
     MyKeyEventFilter myKeyEventFilter;
    app.installEventFilter(&amp;myKeyEventFilter);

    //QML
    qmlRegisterType&lt; SystemController &gt;  ("MyController",1,0,"SystemController");

    QQmlApplicationEngine engine;

    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&amp;engine, &amp;QQmlApplicationEngine::objectCreated,
                     &amp;app, [url](QObject *obj, const QUrl &amp;objUrl) {
        if (!obj &amp;&amp; url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
    return app.exec();
}
</code></pre>
<p dir="auto">The <code>SystemController</code> I used to exchange data beetwen my logic and QML.</p>
<p dir="auto">Is it possible use <code>installEventFilter</code> inside <code>SystemController</code> and events would be works on whole application ? Thanks this, the signal from <code>MyKeyEventFilter</code> I would connect to slot in other object created inside System Controller. now is impossible, i am right ?</p>
<p dir="auto">I try liake below:</p>
<pre><code>
SystemController::SystemController(QObject *parent)
    : QObject{parent}
{

    MyKeyEventFilter myKeyEventFilter;
    this-&gt;installEventFilter(&amp;myKeyEventFilter);
}
</code></pre>
<p dir="auto">and I  removed form main.cpp, but in this way  events doesn't work....</p>
]]></description><link>https://forum.qt.io/topic/141965/keyeventfilter-place-create-object</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 09:50:47 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/141965.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Jan 2023 09:16:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to keyeventfilter place create object on Fri, 06 Jan 2023 12:49:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> The MyKeyEventFilter works all the time when app is turn.<br />
I solved my problem by integrate QML with qt by:</p>
<p dir="auto"><code>engine.rootContext()-&gt;setContextProperty("myobject", myobject);</code></p>
]]></description><link>https://forum.qt.io/post/742790</link><guid isPermaLink="true">https://forum.qt.io/post/742790</guid><dc:creator><![CDATA[Damian7546]]></dc:creator><pubDate>Fri, 06 Jan 2023 12:49:06 GMT</pubDate></item><item><title><![CDATA[Reply to keyeventfilter place create object on Sat, 07 Jan 2023 16:03:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/joecfd">@<bdi>JoeCFD</bdi></a> said in <a href="/post/742854">keyeventfilter place create object</a>:</p>
<blockquote>
<p dir="auto">this kind of definition MyKeyEventFilter myKeyEventFilter; can be fatal in your app sometimes.</p>
</blockquote>
<p dir="auto">I would be really grateful if you could explain me why ?</p>
]]></description><link>https://forum.qt.io/post/742916</link><guid isPermaLink="true">https://forum.qt.io/post/742916</guid><dc:creator><![CDATA[Damian7546]]></dc:creator><pubDate>Sat, 07 Jan 2023 16:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to keyeventfilter place create object on Fri, 06 Jan 2023 16:43:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/damian7546">@<bdi>Damian7546</bdi></a> you may pay more attention to what SGaist said. Try to use more heap space(pointers), especially Qt items or classes.<br />
this kind of definition MyKeyEventFilter myKeyEventFilter; can be fatal in your app sometimes.<br />
Try to use pointer: auto myKeyEventFilter = new MyKeyEventFilter;</p>
]]></description><link>https://forum.qt.io/post/742854</link><guid isPermaLink="true">https://forum.qt.io/post/742854</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Fri, 06 Jan 2023 16:43:03 GMT</pubDate></item><item><title><![CDATA[Reply to keyeventfilter place create object on Fri, 06 Jan 2023 12:49:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> The MyKeyEventFilter works all the time when app is turn.<br />
I solved my problem by integrate QML with qt by:</p>
<p dir="auto"><code>engine.rootContext()-&gt;setContextProperty("myobject", myobject);</code></p>
]]></description><link>https://forum.qt.io/post/742790</link><guid isPermaLink="true">https://forum.qt.io/post/742790</guid><dc:creator><![CDATA[Damian7546]]></dc:creator><pubDate>Fri, 06 Jan 2023 12:49:06 GMT</pubDate></item><item><title><![CDATA[Reply to keyeventfilter place create object on Thu, 05 Jan 2023 19:58:02 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">What is the lifetime of MyKeyEventFilter in SystemController's constructor ?</p>
]]></description><link>https://forum.qt.io/post/742692</link><guid isPermaLink="true">https://forum.qt.io/post/742692</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 05 Jan 2023 19:58:02 GMT</pubDate></item></channel></rss>