首先,看了许多例子,都会出现xxxx module not installed!
发的文章也都是抄来抄去,没啥意思,说的让人半懂不懂。
经过反反复复的折腾,终于弄出来了。
描述:QT5.11 win10
1.qml文件并不能完全的隐藏方法。意思就是说你新建了一个工程,引用这个模块,需要
注:第二个文件名称为plugins.qmltypes。因为我截图截错了,下图同。(不再标明)
这4个或者5个文件,如果缺少qml文件(debug编译使用xxxxxxd.dll.release使用xxxxxx.dll)
所以,只有dll和qmldir是不行的。
2.qmldir内容
module com.mycompany.qmlcomponents
plugin QMLPlugin
typeinfo plugins.qmltypes
MyRect 1.0 MyRect.qml
designersupported
3.import路径问题
pro文件的path应该为A处
QML_IMPORT_PATH = E:\QML_Custom_model
main.cpp
engine.addImportPath("E:/QML_Custom_model");
4.plugins.qmltypes
import QtQuick.tooling 1.2
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump com.mycompany.qmlcomponents 1.0 E:\T\QMLPlugin\QMLPluginTest'
Module {
dependencies: []
Component {
name: "MyItem"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["MyItem 1.0"]
exportMetaObjectRevisions: [0]
}
Component {
name: "QQuickItem"
defaultProperty: "data"
prototype: "QObject"
Enum {
name: "TransformOrigin"
values: {
"TopLeft": 0,
"Top": 1,
"TopRight": 2,
"Left": 3,
"Center": 4,
"Right": 5,
"BottomLeft": 6,
"Bottom": 7,
"BottomRight": 8
}
}
Property { name: "parent"; type: "QQuickItem"; isPointer: true }
Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }
Property { name: "resources"; type: "QObject"; isList: true; isReadonly: true }
Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }
Property { name: "x"; type: "double" }
Property { name: "y"; type: "double" }
Property { name: "z"; type: "double" }
Property { name: "width"; type: "double" }
Property { name: "height"; type: "double" }
Property { name: "opacity"; type: "double" }
Property { name: "enabled"; type: "bool" }
Property { name: "visible"; type: "bool" }
Property { name: "visibleChildren"; type: "QQuickItem"; isList: true; isReadonly: true }
Property { name: "states"; type: "QQuickState"; isList: true; isReadonly: true }
Property { name: "transitions"; type: "QQuickTransition"; isList: true; isReadonly: true }
Property { name: "state"; type: "string" }
Property { name: "childrenRect"; type: "QRectF"; isReadonly: true }
Property { name: "anchors"; type: "QQuickAnchors"; isReadonly: true; isPointer: true }
Property { name: "left"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "right"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "horizontalCenter"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "top"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "bottom"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "verticalCenter"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "baseline"; type: "QQuickAnchorLine"; isReadonly: true }
Property { name: "baselineOffset"; type: "double" }
Property { name: "clip"; type: "bool" }
Property { name: "focus"; type: "bool" }
Property { name: "activeFocus"; type: "bool"; isReadonly: true }
Property { name: "activeFocusOnTab"; revision: 1; type: "bool" }
Property { name: "rotation"; type: "double" }
Property { name: "scale"; type: "double" }
Property { name: "transformOrigin"; type: "TransformOrigin" }
Property { name: "transformOriginPoint"; type: "QPointF"; isReadonly: true }
Property { name: "transform"; type: "QQuickTransform"; isList: true; isReadonly: true }
Property { name: "smooth"; type: "bool" }
Property { name: "antialiasing"; type: "bool" }
Property { name: "implicitWidth"; type: "double" }
Property { name: "implicitHeight"; type: "double" }
Property { name: "containmentMask"; revision: 11; type: "QObject"; isPointer: true }
Property { name: "layer"; type: "QQuickItemLayer"; isReadonly: true; isPointer: true }
Signal {
name: "childrenRectChanged"
Parameter { type: "QRectF" }
}
Signal {
name: "baselineOffsetChanged"
Parameter { type: "double" }
}
Signal {
name: "stateChanged"
Parameter { type: "string" }
}
Signal {
name: "focusChanged"
Parameter { type: "bool" }
}
Signal {
name: "activeFocusChanged"
Parameter { type: "bool" }
}
Signal {
name: "activeFocusOnTabChanged"
revision: 1
Parameter { type: "bool" }
}
Signal {
name: "parentChanged"
Parameter { type: "QQuickItem"; isPointer: true }
}
Signal {
name: "transformOriginChanged"
Parameter { type: "TransformOrigin" }
}
Signal {
name: "smoothChanged"
Parameter { type: "bool" }
}
Signal {
name: "antialiasingChanged"
Parameter { type: "bool" }
}
Signal {
name: "clipChanged"
Parameter { type: "bool" }
}
Signal {
name: "windowChanged"
revision: 1
Parameter { name: "window"; type: "QQuickWindow"; isPointer: true }
}
Signal { name: "containmentMaskChanged"; revision: 11 }
Method { name: "update" }
Method {
name: "grabToImage"
revision: 2
type: "bool"
Parameter { name: "callback"; type: "QJSValue" }
Parameter { name: "targetSize"; type: "QSize" }
}
Method {
name: "grabToImage"
revision: 2
type: "bool"
Parameter { name: "callback"; type: "QJSValue" }
}
Method {
name: "contains"
type: "bool"
Parameter { name: "point"; type: "QPointF" }
}
Method {
name: "mapFromItem"
Parameter { type: "QQmlV4Function"; isPointer: true }
}
Method {
name: "mapToItem"
Parameter { type: "QQmlV4Function"; isPointer: true }
}
Method {
name: "mapFromGlobal"
revision: 7
Parameter { type: "QQmlV4Function"; isPointer: true }
}
Method {
name: "mapToGlobal"
revision: 7
Parameter { type: "QQmlV4Function"; isPointer: true }
}
Method { name: "forceActiveFocus" }
Method {
name: "forceActiveFocus"
Parameter { name: "reason"; type: "Qt::FocusReason" }
}
Method {
name: "nextItemInFocusChain"
revision: 1
type: "QQuickItem*"
Parameter { name: "forward"; type: "bool" }
}
Method { name: "nextItemInFocusChain"; revision: 1; type: "QQuickItem*" }
Method {
name: "childAt"
type: "QQuickItem*"
Parameter { name: "x"; type: "double" }
Parameter { name: "y"; type: "double" }
}
}
}
生成描述文件的方法:
格式:qmlplugindump Arg1 Arg2 Arg3
Arg1 :module名称 Arg2 :module版本 Arg3:插件所在的父路径
1.进入cmd ,cd E:\QML_Custom_model
2.执行qmlplugindump com.mycompany.qmlcomponents 1.0 E:\QML_Custom_model\plugins.qmltypes
至此,关键部分的讲解都已经说完了。这是别人留下的坑。。。。。。。。。。