草庐IT

qmlRegisterType

全部标签

c++ - 无法使 qmlRegisterType 工作

我在Internet上找到了一些qmlRegisterType的示例,但无法使其正常工作。我创建一个新的QtQuick2项目并添加以下内容:这是我的.pro文件:#Addmorefolderstoshipwiththeapplication,herefolder_01.source=qml/testlibfolder_01.target=qmlDEPLOYMENTFOLDERS=folder_01#LibrariesQT+=coreguiwidgets#AdditionalimportpathusedtoresolveQMLmodulesinCreator'scodemodelQML_

c++ - Qt/QML qmlRegisterType 与 setContextProperty(区别)

在Qt/QML应用程序中(此代码通常驻留在QtCreator项目的main.cpp中),以下几种方式将C++类暴露给QML有什么区别:qmlRegisterType("com.example",1,0,"UePeopleModel");和engine.rootContext()->setContextProperty("uePeopleModel",uePeopleModel);? 最佳答案 qmlRegisterType:“有时QObject派生类可能需要在QML类型系统中注册,但不需要作为可实例化的类型。”如果你想在一个或多个具