QML plug-in extension 2 (c + +-based plug-in extension)

Source: Internet
Author: User

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's 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 " Span style= "color: #000000;" >] 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.