当前位置:网站首页>Configuration software -- control import
Configuration software -- control import
2022-06-11 07:28:00 【Fantastical Yu ruiyin】
Catalog
Configuration software – Control import
I have been using it recently Qt Make configuration software , At the beginning with QGraphics To do configuration software UI Design procedure , No kidding , To be honest, it looks a bit like , But there are big problems in the subsequent secondary development , So the second time is for reference feiyangqingyun Great God's attribute design idea , It can be said that it went very smoothly 10 Most of the work was finished in days .
First of all, let's show the effect 
Realization function
Control loading
Related instructions
This part of the code is completely plagiarized feiyangqingyun Great God control loaded program , Don't ask why , Because this code is really powerful , I can't ask any questions , But this part of the code may not conform to my habit of writing programs , I usually like to write a function directly into one QObject In a class of , In this way, the function can be realized by binding the corresponding type of control with the pointer when calling the function , So there is a little difference
Program
//pluginInsert.h
#ifndef PLUGININSERT_H
#define PLUGININSERT_H
/******* * function ------ Bind one listwidget, And realize the loading of the control library * The most important function pluginInsert, To use this function, you must call , The second constructor is recommended * The most important parameter listWidgets、listNames Control list and name list parameters , It can be used for subsequent control generation ******/
#include <QObject>
#include <QListWidget>
#include <QtDesigner/QDesignerCustomWidgetInterface>
#include <QStringList>
#include <QPluginLoader>
#include <QtDesigner/QDesignerCustomWidgetCollectionInterface>
class pluginInsert :public QObject // Import UI Used by plug-ins , Bind one listwidget, The default import quc The plug-in of the control group of
{
Q_OBJECT
public:
pluginInsert(QObject *parent = nullptr);
pluginInsert(QListWidget **widget,QObject *parent = nullptr);
void setlistwidget(QListWidget **widget);
QList<QDesignerCustomWidgetInterface *> listWidgets; // Control list parameters 1
QStringList listNames; // Control list parameters 2
private:
void initPlugin();
void loadPlugin(const QString &fileName);
void openPlugin(const QString &fileName);
QListWidget *listwidget;
};
#endif // PLUGININSERT_H
#include "plugininsert.h"
#include <QApplication>
pluginInsert::pluginInsert(QObject *parent)
:QObject(parent)
{
listwidget=nullptr;
}
pluginInsert::pluginInsert(QListWidget **widget, QObject *parent)
:QObject(parent)
{
setlistwidget(widget);
}
void pluginInsert::setlistwidget(QListWidget **widget)
{
listwidget=*widget;
initPlugin();
}
void pluginInsert::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 default control xml data
//openFile(qApp->applicationDirPath() + "/quc.xml");
qApp->processEvents();
//ui->listWidget->verticalScrollBar()
}
void pluginInsert::loadPlugin(const QString &fileName)
{
openPlugin(fileName);
// this->setWindowTitle(QString(" Custom control property designer ( common %1 Controls )
}
void pluginInsert::openPlugin(const QString &fileName)
{
qDeleteAll(listWidgets);
listWidgets.clear();
listNames.clear();
listwidget->clear();
// Load custom control plug-in collection information , Including getting class names + Icon
QPluginLoader loader(fileName);
if (loader.load()) {
QObject *plugin = loader.instance();
// Get plug-in container , Then walk through the container one by one to find a single plug-in
QDesignerCustomWidgetCollectionInterface *interfaces = qobject_cast<QDesignerCustomWidgetCollectionInterface *>(plugin);
if (interfaces) {
listWidgets = interfaces->customWidgets();
int count = listWidgets.count();
for (int i = 0; i < count; i++) {
QIcon icon = listWidgets.at(i)->icon();
QString className = listWidgets.at(i)->name();
QListWidgetItem *item = new QListWidgetItem(listwidget);
item->setText(className);
item->setIcon(icon);
listNames << className;
}
}
// Get the class names of all plug-ins
const QObjectList objList = plugin->children();
foreach (QObject *obj, objList) {
QString className = obj->metaObject()->className();
//qDebug() << className;
}
}
}
This part of the program is a complete version ,listwidget After binding a control, the control import function can be realized . But the premise is that it must be compiled exe Under path by quc.dll and libquc.lib Two documents , Otherwise, the display is still blank .
Reference blog
https://qtchina.blog.csdn.net/article/details/100652152
边栏推荐
- 【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算
- 1300. the array closest to the target value after transforming the array and
- @JsonProperty注解
- Experience record of rural housing integration script
- Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
- QT table display data
- Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
- Leetcode-104. Maximum Depth of Binary Tree
- Atomicinteger atomic operation class
- 【CF #277.5 (Div. 2)】B. BerSU Ball
猜你喜欢

JVM学习记录(七)——类加载过程与双亲委派模型

If you want to save an IP address, what data type is better? 99% of people will answer wrong!

Outer margin collapse
![[Oracle database] mammy tutorial day04 Sorting Query](/img/79/9db26aa2d9dbb5514427edf03004f4.png)
[Oracle database] mammy tutorial day04 Sorting Query

Education expert Mr. wangzhongze: family education focuses on self growth
![[STL source code analysis] summary notes (12): functors and adapters](/img/6d/a3a9cde2c8792579af7505c2226914.jpg)
[STL source code analysis] summary notes (12): functors and adapters

软件测试周刊(第75期):唯有平视,才能看见真实的自己。
![[STL source code analysis] summary notes (10): hashtable exploration](/img/31/a77ac380dbd0f85957bd1df1b906f5.jpg)
[STL source code analysis] summary notes (10): hashtable exploration

一、SQLServer2008安裝(帶密碼)、創建數據庫、C#窗體項目測試

Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation
随机推荐
软件测试周刊(第75期):唯有平视,才能看见真实的自己。
Cartland number application
Crmeb/v4.4 Standard Version open version mall source code applet official account h5+app mall source code
Typora set markdown syntax inline mode
Android and IOS reverse analysis / security detection / penetration testing framework
Summary of written test questions of shopee 2021 autumn recruitment
【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算
Android和iOS逆向分析/安全检测/渗透测试框架
【CF#223 (Div. 2)】A. Sereja and Dima
Biological sequence intelligent analysis platform blog (1)
JVM学习记录(七)——类加载过程与双亲委派模型
Adventure of small X
Directrix of ellipse
Ffmpe a small demo to understand 80% of common APIs
MS office level II wrong question record [6]
[STL source code analysis] summary notes (7): ingenious deque
big. Js-- use / instance
1269. number of options left in place
Ffmpeg extraction package format extracts AAC and customizes adtc header to realize arbitrary frame decoding
10 advanced concepts that must be understood in learning SQL