Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to load plug-ins in Qt

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "Qt how to load plug-ins", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Qt how to load plug-ins" this article.

I. Preface

Loading the plug-in is the first step of the entire property designer to get through the function. The controls in the plug-in cannot be loaded, so don't play with them later. To load the control from a dynamic library, you definitely need to use the reflection mechanism. In the past, when you were doing .NET development, you felt that reflection was quite powerful. You can actually read DLL and load out controls. Now you can use Qt to find that Qt also has a reflection mechanism. Perhaps this thing may be available on all major development language platforms. The corresponding class of Qt reflection is called QMetaObject, which is really powerful. In fact, the whole Qt development framework is also super powerful. Since I turned to Qt development, I have fallen in love with her deeply. In front of other cross-platform GUI development framework platforms, they will be slagged in Qt seconds. There is no doubt about the cross-platform nature of Qt. It can be run with tens of megabytes of memory space. Especially when the resource of embedded linux is very tight, the performance of Qt is extreme.

II. Functional features

Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.

Drag to the canvas to automatically generate the corresponding control, WYSIWYG.

On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.

The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.

The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.

Support manual selection of plug-in files, external import plug-in files.

You can export all control configuration information for the current canvas to a xml file.

You can manually select the xml file to open the control layout and automatically load the control according to the xml file.

Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.

The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.

Through the serial port acquisition, network acquisition, database collection of three ways to set data.

The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.

Pure Qt writing, support any Qt version + any compiler + any system.

Third, effect picture

4. Core code void frmMain::initPlugin () {/ / load the default plug-in # if defined (Q_OS_WIN) QString pluginName = QString ("% 1/quc.dll") .arg (qApp- > applicationDirPath ()); # elif defined (Q_OS_UNIX) QString pluginName = QString ("% 1/libquc.so") .arg (qApp- > applicationDirPath ()) # elif defined (Q_OS_MAC) QString pluginName = QString ("% 1/libquc.dylib") .arg (qApp- > applicationDirPath ()); # endif loadPlugin (pluginName); / / load the default control xml data openFile (qApp- > applicationDirPath () + "/ quc.xml"); qApp- > processEvents (); ui- > listWidget- > verticalScrollBar ()-> setValue (0);} void frmMain::loadPlugin (const QString & fileName) {openPlugin (fileName) This- > setWindowTitle (QString ("Custom Control property designer (1 controls total) (QQ:517216493)") .arg (ui- > listWidget- > count ());} void frmMain::openPlugin (const QString & fileName) {qDeleteAll (listWidgets); listWidgets.clear (); listNames.clear (); ui- > listWidget- > clear (); / / load custom control plug-in collection information, including obtaining class name + icon QPluginLoader loader (fileName) If (loader.load ()) {QObject * plugin = loader.instance (); / / get the plug-in container, and then traverse the container one by one to find a single plug-in QDesignerCustomWidgetCollectionInterface * interfaces = qobject_cast (plugin); if (interfaces) {listWidgets = interfaces- > customWidgets (); int count = listWidgets.count (); for (plug-in I = 0; I

< count; i++) { QIcon icon = listWidgets.at(i)->

Icon (); QString className = listWidgets.at (I)-> name (); QListWidgetItem * item = new QListWidgetItem (ui- > listWidget); item- > setText (className); item- > setIcon (icon); listNames children (); foreach (QObject * obj, objList) {QString className = obj- > metaObject ()-> className () / / qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report