Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. keyeventfilter place create object

keyeventfilter place create object

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 430 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    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 SystemController I used to exchange data beetwen my logic and QML.

    Is it possible use installEventFilter inside SystemController and events would be works on whole application ? Thanks this, the signal from MyKeyEventFilter I 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....

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Damian7546
      wrote on last edited by
      #3

      @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);

      JoeCFDJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        What is the lifetime of MyKeyEventFilter in SystemController's constructor ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Damian7546
          wrote on last edited by
          #3

          @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);

          JoeCFDJ 1 Reply Last reply
          0
          • D Damian7546

            @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);

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #4

            @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;

            D 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @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;

              D Offline
              D Offline
              Damian7546
              wrote on last edited by
              #5

              @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 ?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved