The previous section describes the plug-in extension of pure qml, which basically satisfies most of the expansion requirements, and starts with a smaller set of C + +-based extensions
(i) Update the plug-in project
1. Update the Qmldir file under Myplugin project, add plugin myplugin, where Myplugin is the dynamic library name of the plugin, Under Windows corresponds to MyPlugin.dll, under Linux for more than a month myplugin.so
2. Compile the Myplugin plugin, generate the MyPlugin.dll, there is no copy configuration for the project, so the default DLL is not copied to e:/t/qmlplugin/qmlplugintest/, manual copy is required,
3. At this time, you can use the MAIN.QML in the app,
(ii) Generate plug-in description file Qmltypes
1. In this example, because the plug-in and the app in the same large directory project, so myitem will automatically highlight, if not in the same directory project, there will be no highlighting and prompting, it is necessary to Qmltypes description file to support highlighting
2. In this example, the Myplugin.pro file can be first from the directory Project next, in the open restart Qtcreator, you can see the app's MAIN.QML application myitem There are wavy lines
3. Call Qmlplugindump to generate the description file:
Qmlplugindump Myplugin 1.0 E:\T\QMLPlugin\QMLPluginTest > E:\T\QMLPlugin\QMLPluginTest\MyPlugin\plugin.qmltypes
The description file is generated automatically:
Import Qtquick.tooling 1.1//This file describes the Plugin-supplied types contained in the library.//It is used for QML tooling purposes only.// //This file is auto-generated by://' qmlplugindump myplugin 1.0 E:\T\QMLPlugin\QMLPluginTest 'Module {Component {name:"MyItem"Defaultproperty:"Data"prototype:"Qquickitem"exports: ["MyItem 1.0"] Exportmetaobjectrevisions: [0] } }
4. Open the Myplugin project again, plus this sentence:typeinfo plugin.qmltypes
Report:
1. If you want to write your own C + + extension, you can study the Qtquick.controls source code
2. Example code for this section: https://github.com/youngerking1985/QML_Learn/tree/master/QMLPlugin2
Note:
1. Qmlplugindump will distinguish between release and debug, it is recommended to compile the release directly
2. If the plugin has a DLL other than QT (not recommended), you need to put the DLL in the same directory as Qmlplugindump
3. If the DLL plug-in method written in C + + is used, the module name cannot be duplicated with the mudule registered inside the EXE.
QML plug-in extension 2 (c + +-based plug-in extension)