Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

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

    QML and Qt Quick
    qt creator qml setcontextprope c++ windows auto completion
    3
    4
    556
    Loading More Posts
    • 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_titov
      a_titov last edited by

      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-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @a_titov last edited by

        @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_titov 1 Reply Last reply Reply Quote 0
        • a_titov
          a_titov @raven-worx last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • T
            themts last edited by

            Hello guys,

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post