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. Qmlls.exe not find C++ Custom Types
Forum Updated to NodeBB v4.3 + New Features

Qmlls.exe not find C++ Custom Types

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 331 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.
  • K Offline
    K Offline
    khtkg
    wrote on last edited by khtkg
    #1

    Qmlls.exe has some warings, but the program can run.

    The demo come from https://doc.qt.io/qt-6/qtqml-tutorials-extending-qml-example.html

    I need to use the code prompt feature of qmls.exe, so please do not disabled qmls.exe.

    Program Running:
    07510dd9-4803-464f-a6b9-611d6344ee9a-1732932800586.png

    But qmls.exe prompts some warnings:
    a9b24bcd-0366-4673-a625-33571ade05e3-1732932895023.png

    I have tried the following methods:

    • Attempted restarting qmls.exe, but failed
    • qmlRegisterType<>(), but failed
    • Clear cache, but failed
    • Use another clean Windows system, but failed

    I need to use the code prompt feature of qmls.exe, so please do not disabled qmls.exe.

    This is a demo:

    piechart.h

    #ifndef PIECHART_H
    #define PIECHART_H
    
    #include <QQuickPaintedItem>
    #include <QColor>
    #include <QPen>
    #include <QPainter>
    
    class PieChart : public QQuickPaintedItem
    {
        Q_OBJECT
        Q_PROPERTY(QString name READ name WRITE setName NOTIFY onNameChanged FINAL)
        Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY onColorChaged FINAL)
        QML_ELEMENT
    
    public:
        PieChart(QQuickItem *parent = nullptr);
    
        QString name() const;
        void setName(const QString &name);
    
        QColor color() const;
        void setColor(const QColor &color);
    
        void paint(QPainter *painter) override;
    
    signals:
        void onNameChanged();
        void onColorChaged();
    
    private:
        QString m_name;
        QColor m_color;
    };
    
    #endif // PIECHART_H
    

    piechart.cpp

    #include "piechart.h"
    
    PieChart::PieChart(QQuickItem *parent) {}
    
    QString PieChart::name() const
    {
        return m_name;
    }
    
    void PieChart::setName(const QString &name)
    {
        m_name = name;
    }
    
    QColor PieChart::color() const
    {
        return m_color;
    }
    
    void PieChart::setColor(const QColor &color)
    {
        m_color = color;
    }
    
    void PieChart::paint(QPainter *painter)
    {
        QPen pen(m_color, 2);
        painter->setPen(pen);
        painter->setRenderHints(QPainter::Antialiasing, true);
        painter->drawPie(boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16);
    }
    
    

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        QObject::connect(
            &engine,
            &QQmlApplicationEngine::objectCreationFailed,
            &app,
            []() { QCoreApplication::exit(-1); },
            Qt::QueuedConnection);
        engine.loadFromModule("Demo", "Main");
    
        return app.exec();
    }
    
    

    main.qml

    import QtQuick
    import Demo
    
    Window {
        width: 300
        height: 200
        visible: true
        title: qsTr("Hello World")
    
        PieChart {
            id: aPieChart
            anchors.centerIn: parent
            width: 100; height: 100
            name: "A simple pie chart"
            color: "red"
        }
    
        Text {
            anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
            text: aPieChart.name
        }
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.16)
    
    project(Demo VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 6.5 REQUIRED COMPONENTS Core Gui Qml Quick)
    
    qt_standard_project_setup(REQUIRES 6.5)
    
    qt_add_executable(appDemo
        main.cpp
    )
    
    set_target_properties(appDemo PROPERTIES
        WIN32_EXECUTABLE TRUE
        MACOSX_BUNDLE TRUE
    )
    
    qt_add_qml_module(appDemo
        URI Demo
        VERSION 1.0
        QML_FILES Main.qml
        SOURCES piechart.h piechart.cpp
    )
    
    # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
    # If you are developing for iOS or macOS you should consider setting an
    # explicit, fixed bundle identifier manually though.
    set_target_properties(appDemo PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appDemo
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_link_libraries(appDemo
        PUBLIC
        Qt6::Core
        Qt6::Gui
        Qt6::Qml
        Qt6::Quick
    )
    
    include(GNUInstallDirs)
    install(TARGETS appDemo
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    

    Can you tell me how to solve it? I need to use the code prompt feature of qmls.exe, so please do not disabled qmls.exe.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chids
      wrote on last edited by
      #2

      add:
      set(QT_QML_GENERATE_QMLLS_INI ON)
      to CMakeLists.txt, i had the same issue too

      K 1 Reply Last reply
      0
      • C chids

        add:
        set(QT_QML_GENERATE_QMLLS_INI ON)
        to CMakeLists.txt, i had the same issue too

        K Offline
        K Offline
        khtkg
        wrote on last edited by
        #3

        @chids
        This doesn't work for me。

        I have restarted qmls.exe and cleared CmakeCache。

        dab4ef0f-d534-4781-a9f1-bc09388309e4-1733118107337.png

        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