当前位置:网站首页>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
边栏推荐
- Pointer to a two-dimensional array
- Android和iOS逆向分析/安全检测/渗透测试框架
- QT table display data
- Sqlzoo question brushing record-3
- May 30-June 5, 2022 AI industry weekly (issue 100): three years
- [STL source code analysis] summary notes (5): a good helper for understanding iterators --list
- big.js--使用/实例
- Nosqlzoo question brushing-1
- Android and IOS reverse analysis / security detection / penetration testing framework
- 二、用户登录和注册
猜你喜欢

2、 User login and registration

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

QT table display data

Use definite integral to calculate triangle area

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

Senior openstacker - Bloomberg, vexxhost upgraded to gold member of openinfra Foundation

Leetcode-104. Maximum Depth of Binary Tree

【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算

Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation

Qstring to hexadecimal qstring
随机推荐
[analysis of STL source code] summary notes (3): vector introduction
Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
Server parameter adjustment record
【CF#654 (Div. 2)】A. Magical Sticks
Mybags puls will report an error invalid bound statement (not found) when writing an SQL statement in the XML file:
Several transaction modes of Seata
MS office level II wrong question record [9]
Matplotlib, set coordinate scale size, font / set legend size and font / set vertical and horizontal coordinate name, font and size
Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
RTMP protocol
Interview question 02.06 Palindrome linked list
Compound ratemodel contract analysis
P5431 [template] multiplicative inverse 2
Typora set markdown syntax inline mode
Software testing weekly (issue 75): only when you look down, can you see your true self.
【CF#697 (Div. 3)】 A - Odd Divisor
[STL source code analysis] summary notes (5): a good helper for understanding iterators --list
Post-processing of ffmpeg miscellaneous notes
Pointer to a two-dimensional array
[Oracle database] mammy tutorial day02 use of database management tool sqlplus