Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt 6.9 and QML harmony?
Forum Updated to NodeBB v4.3 + New Features

Qt 6.9 and QML harmony?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 4 Posters 400 Views 4 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote last edited by
    #2

    Hi,

    AFAIR, you should setup your properties before loading your qml files.

    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
    • MucipM Offline
      MucipM Offline
      Mucip
      wrote last edited by Mucip
      #3

      Hi,
      I did everything according to tutorial.
      He can see code compilation but I can not see.
      But all codes are working as expected without any problem.
      The tutorial made in Qt5 and I work now in Qt6.

      Regards,
      Mucip:)

      jeremy_kJ 1 Reply Last reply
      0
      • MucipM Mucip

        Hi,
        I did everything according to tutorial.
        He can see code compilation but I can not see.
        But all codes are working as expected without any problem.
        The tutorial made in Qt5 and I work now in Qt6.

        Regards,
        Mucip:)

        jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote last edited by
        #4

        @Mucip said in Qt 6.9 and QML harmony?:

        Hi,
        I did everything according to tutorial.

        Which tutorial?

        The tutorial made in Qt5 and I work now in Qt6.

        There must be a misunderstanding.
        QQmlApplicationEngine::loadFromModule():

        This function was introduced in Qt 6.5.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0
        • MucipM Offline
          MucipM Offline
          Mucip
          wrote last edited by
          #5

          Hi,
          Tutorial is: https://www.youtube.com/watch?v=Tq-E6lqO6tM

          Regards,
          Mucip:)

          jeremy_kJ 1 Reply Last reply
          0
          • MucipM Mucip

            Hi,
            Tutorial is: https://www.youtube.com/watch?v=Tq-E6lqO6tM

            Regards,
            Mucip:)

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote last edited by
            #6

            @Mucip said in Qt 6.9 and QML harmony?:

            Hi,
            Tutorial is: https://www.youtube.com/watch?v=Tq-E6lqO6tM

            Too long (didn't watch) for me. As @SGaist mentions, setting up the context property should happen before attempting to load the root component. If the tutorial demonstrated loading from a remote source, it might have worked generally worked despite the race condition.

            https://doc.qt.io/qt-6/qqmlapplicationengine.html#loadFromModule

            If the type originates from a QML file located at a remote url, the type will be loaded asynchronously.

            I interpret this as an indication that a file from a local url will be loaded synchronously.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            1
            • MucipM Offline
              MucipM Offline
              Mucip
              wrote last edited by
              #7

              Hi,
              Yes. It's long but perfect tutorial. :)
              My main.cpp was like below first. When I move signed code to the up then "Reference error: Not defined" errors disappeared.
              But I can not see code compilation of cpp file from qml file?!

              resim.png

              Regards,
              Mucip:)

              1 Reply Last reply
              0
              • MucipM Offline
                MucipM Offline
                Mucip
                wrote last edited by Mucip
                #8

                Hi,
                The main problem is intellisense, code compilation doesnt'work.
                But program is working anyways...

                Is there any basic helloworld doument how to bind cpp functions to QML but in CMake version?

                Regards,
                Mucip:)

                SGaistS 1 Reply Last reply
                0
                • MucipM Mucip

                  Hi,
                  The main problem is intellisense, code compilation doesnt'work.
                  But program is working anyways...

                  Is there any basic helloworld doument how to bind cpp functions to QML but in CMake version?

                  Regards,
                  Mucip:)

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote last edited by
                  #9

                  @Mucip whether using qmake or cmake has no influence on the issue at hand. It's really just doing things in the correct order in the code part.

                  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
                  • MucipM Offline
                    MucipM Offline
                    Mucip
                    wrote last edited by
                    #10

                    Dear Sgaist
                    Well, Where should I make mistake than? Could you check please? Program is working but no intellisense.

                    #include <QGuiApplication>
                    #include <QQmlApplicationEngine>
                    #include <QQmlContext>
                    
                    #include <Controllers/system.h>
                    #include <Controllers/hvachandler.h>
                    
                    int main(int argc, char *argv[])
                    {
                    
                    #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
                        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                    
                    #endif
                    
                        QGuiApplication app(argc, argv);
                    
                        static System m_systemHandler;
                        HVACHandler m_driverHVACHandler;
                        HVACHandler m_passangerHVACHandler;
                    
                    
                        QQmlApplicationEngine engine;
                    
                        QQmlContext * context(engine.rootContext());
                    
                        context->setContextProperty("systemHandler", &m_systemHandler);
                    
                        context->setContextProperty("driverHVAC", &m_driverHVACHandler);
                        context->setContextProperty("passangerHVAC", &m_passangerHVACHandler);    
                    
                    
                        QObject::connect(
                            &engine,
                            &QQmlApplicationEngine::objectCreationFailed,
                            &app,
                            []() { QCoreApplication::exit(-1); },
                            Qt::QueuedConnection);
                        
                        engine.loadFromModule("TeslaPanel", "Main");
                    
                    
                        return app.exec();
                    }
                    
                    

                    Reards,
                    Mucip:)

                    JKSHJ 1 Reply Last reply
                    0
                    • MucipM Mucip

                      Dear Sgaist
                      Well, Where should I make mistake than? Could you check please? Program is working but no intellisense.

                      #include <QGuiApplication>
                      #include <QQmlApplicationEngine>
                      #include <QQmlContext>
                      
                      #include <Controllers/system.h>
                      #include <Controllers/hvachandler.h>
                      
                      int main(int argc, char *argv[])
                      {
                      
                      #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
                          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                      
                      #endif
                      
                          QGuiApplication app(argc, argv);
                      
                          static System m_systemHandler;
                          HVACHandler m_driverHVACHandler;
                          HVACHandler m_passangerHVACHandler;
                      
                      
                          QQmlApplicationEngine engine;
                      
                          QQmlContext * context(engine.rootContext());
                      
                          context->setContextProperty("systemHandler", &m_systemHandler);
                      
                          context->setContextProperty("driverHVAC", &m_driverHVACHandler);
                          context->setContextProperty("passangerHVAC", &m_passangerHVACHandler);    
                      
                      
                          QObject::connect(
                              &engine,
                              &QQmlApplicationEngine::objectCreationFailed,
                              &app,
                              []() { QCoreApplication::exit(-1); },
                              Qt::QueuedConnection);
                          
                          engine.loadFromModule("TeslaPanel", "Main");
                      
                      
                          return app.exec();
                      }
                      
                      

                      Reards,
                      Mucip:)

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote last edited by JKSH
                      #11

                      @Mucip said in Qt 6.9 and QML harmony?:

                      Program is working but no intellisense.

                      If you use setContextProperty() or qmlRegister*() functions, then the classes are only registered AFTER the program starts running. That's why code completion (Intellisense) doesn't work -- because your classes have not been registered so the QML tools can't see your classes.

                      The documentation contains a warning about the problems of context properties: https://doc.qt.io/qt-6/qtqml-cppintegration-contextproperties.html

                      Instead, use the QML_ELEMENT + QML_SINGLETON macro with qt_add_qml_module() to register your class automatically when building your project. Then, code completion can work.

                      The "QML Video" example (https://doc.qt.io/qt-6/qtmultimedia-video-qmlvideo-example.html ) shows how to do this with its VideoSingleton class:

                      • https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimedia/video/qmlvideo/qmlvideo/videosingleton.h?h=6.9
                      • https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimedia/video/qmlvideo/qmlvideo/CMakeLists.txt?h=6.9

                      For more information about integrating C++ and QML, see https://doc.qt.io/qt-6/qtqml-cppintegration-overview.html

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      1 Reply Last reply
                      2

                      • Login

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