Qmlls.exe not find C++ Custom Types
Unsolved
QML and Qt Quick
-
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:
But qmls.exe prompts some warnings:
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.