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. How to fix QML code editor auto-completion for integrated C++ methods?
QtWS25 Last Chance

How to fix QML code editor auto-completion for integrated C++ methods?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt creatorqmlsetcontextpropec++ windowsauto completion
4 Posts 3 Posters 1.4k Views
  • 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.
  • a_titovA Offline
    a_titovA Offline
    a_titov
    wrote on last edited by
    #1

    Hello, All!

    In my QTCreator for QML code auto-completion for integrated C++ methods doesn't work.

    For instance, I did Myclass class and pass object pointer to QML engine by setContextProperty method.

    QQmlApplicationEngine engine;
    Myclass* confptr = new Myclass();
    engine.rootContext()->setContextProperty("testCPP", confptr);
    

    In QML code after I input ...

    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Column {
            spacing: 10
    
            Button {
                onClicked: testCPP.
    

    ... there is no auto-completion popup. So I need copy method name manually from C++ code.

    After running application it works properly but manual inputs disturbs me.

    Can you give an advice, how I can solve this problem?

    Myclass.h

    #ifndef MYCLASS_H
    #define MYCLASS_H
    
    #include <QObject>
    
    class Myclass : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int engineRPM READ engineRPM WRITE setEngineRPM NOTIFY engineRPMChanged)
    public:
        Myclass();
        int engineRPM() const;
    
    signals:
        void engineRPMChanged();
    
    private:
        int m_engineRPM;
    
    public slots:
        void setEngineRPM (int temp);
    
    };
    
    
    
    #endif // MYCLASS_H
    

    Myclass.cpp

    #include "myclass.h"
    #include <QDebug>
    
    Myclass::Myclass()
    {
        setEngineRPM(100);
    }
    
    void Myclass::setEngineRPM (int temp){
    
        m_engineRPM = temp;
        qDebug () << "Some text here" << temp;
    }
    
    int Myclass::engineRPM() const{
    
        return m_engineRPM;
    
    }
    

    Main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    
    #include "myclass.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);
    
        QQmlApplicationEngine engine;
    
        Myclass* confptr = new Myclass();
        confptr->setEngineRPM(1);
    
        engine.rootContext()->setContextProperty("testCPP", confptr);
    
        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();
    }
    

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.12
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Column {
            spacing: 10
    
            Button {
                onClicked: testCPP.setEngineRPM(1000)
            }
    
            Text {
                text: testCPP.engineRPM
            }
        }
    }
    

    I have installed:

    Qt Creator 5.0.0 Based on Qt 5.15.2 (MSVC 2019, 64 bit)

    OS: Windows 10 21H1 build 19043.1415

    raven-worxR 1 Reply Last reply
    0
    • a_titovA a_titov

      Hello, All!

      In my QTCreator for QML code auto-completion for integrated C++ methods doesn't work.

      For instance, I did Myclass class and pass object pointer to QML engine by setContextProperty method.

      QQmlApplicationEngine engine;
      Myclass* confptr = new Myclass();
      engine.rootContext()->setContextProperty("testCPP", confptr);
      

      In QML code after I input ...

      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Column {
              spacing: 10
      
              Button {
                  onClicked: testCPP.
      

      ... there is no auto-completion popup. So I need copy method name manually from C++ code.

      After running application it works properly but manual inputs disturbs me.

      Can you give an advice, how I can solve this problem?

      Myclass.h

      #ifndef MYCLASS_H
      #define MYCLASS_H
      
      #include <QObject>
      
      class Myclass : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(int engineRPM READ engineRPM WRITE setEngineRPM NOTIFY engineRPMChanged)
      public:
          Myclass();
          int engineRPM() const;
      
      signals:
          void engineRPMChanged();
      
      private:
          int m_engineRPM;
      
      public slots:
          void setEngineRPM (int temp);
      
      };
      
      
      
      #endif // MYCLASS_H
      

      Myclass.cpp

      #include "myclass.h"
      #include <QDebug>
      
      Myclass::Myclass()
      {
          setEngineRPM(100);
      }
      
      void Myclass::setEngineRPM (int temp){
      
          m_engineRPM = temp;
          qDebug () << "Some text here" << temp;
      }
      
      int Myclass::engineRPM() const{
      
          return m_engineRPM;
      
      }
      

      Main.cpp

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QQmlContext>
      
      #include "myclass.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);
      
          QQmlApplicationEngine engine;
      
          Myclass* confptr = new Myclass();
          confptr->setEngineRPM(1);
      
          engine.rootContext()->setContextProperty("testCPP", confptr);
      
          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();
      }
      

      main.qml

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.12
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Column {
              spacing: 10
      
              Button {
                  onClicked: testCPP.setEngineRPM(1000)
              }
      
              Text {
                  text: testCPP.engineRPM
              }
          }
      }
      

      I have installed:

      Qt Creator 5.0.0 Based on Qt 5.15.2 (MSVC 2019, 64 bit)

      OS: Windows 10 21H1 build 19043.1415

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @a_titov
      https://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      a_titovA 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @a_titov
        https://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html

        a_titovA Offline
        a_titovA Offline
        a_titov
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • T Offline
          T Offline
          themts
          wrote on last edited by
          #4

          Hello guys,

          I'm quite often facing the same problem.
          Who to fix this problem?

          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