How to write plug-in loading plugin uninstall plugin in QT

Source: Internet
Author: User

How to write plug -in loading plugin Uninstall plugin in Qt is the content that this article describes. QT provides a class Qpluginloader to load static and dynamic libraries, and in Qt, QT uses both dynamic and static libraries as a plug-in, using Qpluginloader to load and unload these libraries. Since the development of the project, to develop a set of plug-in systems, the use of this set of QT class library.

Write a plugin

The following steps are required to write a QT plugin

1. Declare a plug-in class,

2. Define a class that implements the interface defined by this plug-in class, which must be integrated from Qobject.

3. Use Q_interfacesq_interfaces () to inform QT of the existence of the meta-system of this interface

3. Use the macro q_export_plugin2 () to export the plug-in interface

4. Write the. Pro file for the plug-in class

Here is an example of a plugin





5.



Note: The interface class must be a pure virtual function

    1. Q_declare_interface (Filterinterface, "com.trolltech.plugandpaint.brushinterface/1.0")

In order for the program to query whether a plug-in implements a given interface at run time, the macro q_declare_interface () must be used. His first argument is the name of the interface, and the second parameter is a string that determines the interface. For convenience, a Java package naming method is used. If we later change the interface, we must use a new string to confirm the interface. Otherwise, the application may crash, so including a version number is a good way to do it.

1 #include <QObject>
2 #include <QStringList>
3 #include <QImage>

5 #include <plugandpaint/interfaces.h>



9
10


13
14
15

Implement this interface class. The class that implements the interface must derive from Qobject and must implement the virtual functions defined in the interface class.

Q_export_plugin2 (Plugextrafilters, Extrafiltersplugin) because the application function uses the main () function as the entry point, the plug-in must use the macro q_export_plugin2 () to specify that the class provides the plug-in.

This line of code can appear on any line of the. cpp file that implements the interface class. Where the first parameter is the name of the plug-in, and the second parameter is the plug-in class

Second use plug-in




4
5


The Qpluginloader class provides a function loader to load an instance of a plug-in, if the DLL is not a plugin, or if the compiled Qt version library is incorrect, the pointer to the returned Qobject object is empty. Use the Unload function to unload the plug-in.

Three. Preparation of pro Files





5 TARGET = Pnp_extrafilters

Http://www.cnblogs.com/elect-fans/archive/2012/03/20/2408564.html

How to write plug-in loading plugin uninstall plugin in QT

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.