当前位置:网站首页>Creation and call of QT dynamic DLL
Creation and call of QT dynamic DLL
2022-07-22 15:39:00 【God port】
One 、DLL Generation
1. Project file creation
After naming, just go to the next step .
2. Class file creation
In this example, we create 2 Classes to test
The engineering structure is as follows :
CommonToolDll Code :
#ifndef COMMONTOOLDLL_H
#define COMMONTOOLDLL_H
#include "commontooldll_global.h"
class COMMONTOOLDLLSHARED_EXPORT CommonToolDll
{
public:
CommonToolDll();
static double Sum(double a,double b);
};
#endif // COMMONTOOLDLL_H
#include "commontooldll.h"
CommonToolDll::CommonToolDll()
{
}
double CommonToolDll::Sum(double a, double b)
{
return a+b;
}
PrintString Code :
#ifndef PRINTSTRING_H
#define PRINTSTRING_H
#include<QString>
#include "commontooldll_global.h"
class COMMONTOOLDLLSHARED_EXPORT PrintString
{
public:
PrintString();
static QString PrintHexString(QByteArray str);
};
#endif // PRINTSTRING_H
#include "printstring.h"
PrintString::PrintString()
{
}
QString PrintString::PrintHexString(QByteArray str)
{
return str.toHex();
}
matters needing attention : Every new class has to use macros COMMONTOOLDLLSHARED_EXPORT To embellish , Otherwise, we cannot call this class later , This macro is defined in the global header file .
3. structure
Right click project engineering , Just run the build .
4. effect
What we need dll and lib Generated , This example only uses MSVC compiler , If you use MinGW It will generate at the same time .a Library file
Two 、 call
1. Create a new one Widget project
2. Environment configuration
Put the header file written at the beginning into our including In the folder
stay pro Add header file path to :
add to lib Folder flip in dll
Import lib
Right click on the item , Select Add Library -》 External library
And then I saw pro In the document LIBS Has added , Of course, it can also be written manually
Interface test code :
#include "widget.h"
#include "ui_widget.h"
#include"commontooldll.h"
#include"printstring.h"
#include<QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
int a=ui->lineEdit->text().toDouble();
int b=ui->lineEdit_2->text().toDouble();
ui->line_sum->setText(QString::number(a+b));
QByteArray aa("FF");
ui->textEdit->setText(PrintString::PrintHexString(aa));
}
Running effect :
summary :
1. Every class needs to add an external library macro declaration , Otherwise, it cannot be called normally
2. Pay attention to the configuration header file and library file when calling
3. take dll Put it in the project file directory
边栏推荐
- C语言编写九九乘法表,实现不同三角形形状表格输出
- 还在问用什么来做接口测试?万能Jmeter打造性能测试数据平台
- Still asking what to use for interface testing? Universal JMeter creates a performance test data platform
- 调试VBS visual studio
- nacos基础概念和单机启动
- V-IF, V-for, list filtering and sorting, forced binding of class and style, and collection of form information
- 单调栈框架
- AutoLabel(自动标签)
- QT 动态dll的创建和调用
- Code shoe set - mt2201 · sum of all
猜你喜欢
欢乐的彝族火把节Joyous Torch Festival of the Yi Nationality
AutoLabel (AutoLabel)
卷妹的面试小抄每日更新Day1
Bi analytical thinking of business intelligence: cash cycle of manufacturing industry (II)
How to align MathType formula and word text layout
TDengine实验集群搭建 Success
华为云从入门到实战 | AI云开发ModelArts入门与WAF应用与部署
How to select current probe
seaborn barplot画图总结
玩转CANoe,博客目录大全
随机推荐
调试VBS visual studio
Redis高可用原理 主从哨兵集群
Values swxxdp calculation in Res
seaborn barplot画图总结
Halcon displays point clouds in TXT file format
Aidl summary
华为云从入门到实战 | AI云开发ModelArts入门与WAF应用与部署
JMeter notes 1 | introduction and architecture of JMeter
Bannertext (watermark text)
Can Oracle RAC be built on Youxuan database?
海康、大华、宇视拉实时流url规则总结
Still asking what to use for interface testing? Universal JMeter creates a performance test data platform
Summary of URL rules for real-time streaming of Hikvision, Dahua and yushila
【07】函数调用:为什么会发生stack overflow?
LeetCode 0814. 二叉树剪枝
AIDL总结
A simple inventory management system source code
halcon 使用txt文件格式显示点云
Upload pictures to the IIS server of this machine, and the results are returned in the form of web address, which can be accessed directly
Basic concept of Nacos and single machine startup