一、程序编译过程
二、静态库创建和使用
1、新建Mainwindow项目,写一个定时器做测试
a).h
b).cpp
1 #include "staticclass.h" 2 #include "ui_staticclass.h" 3 #include<QTimer> 4 5 staticClass::staticClass(QWidget *parent) 6 : QMainWindow(parent) 7 , ui(new Ui::staticClass) 8 { 9 ui->setupUi(this); 10 steps = 0; 11 12 timer = new QTimer(); 13 connect(timer, &QTimer::timeout, this, &staticClass::updateTime); 14 } 15 16 staticClass::~staticClass() 17 { 18 if(timer) 19 { 20 delete timer; 21 timer = nullptr; 22 } 23 delete ui; 24 } 25 26 27 void staticClass::on_btnStart_clicked() 28 { 29 timer->start(500); 30 } 31 32 void staticClass::updateTime() 33 { 34 ++ steps; 35 ui->lcdNumber->display(QString::number(steps)); 36 } 37 38 void staticClass::on_btnStop_clicked() 39 { 40 timer->stop(); 41 }
c)运行
2、生成静态库
a)创建库项目,注意选择库选项,别选成共享库了
b)将生成的定时器.h/.cpp/.ui文件拷贝至库项目文件夹内,替换掉它的.h/.cpp文件,并加载.ui文件
c)修改.pro文件,因为使用了QMainwindow类,属于widgets
在.pro文件中添加 QT += widgets
d)分别构建库项目的Debug文件夹和Release文件夹,并把两个文件中的.lib文件拷贝出来,其中Debug文件夹的.lib记得在末尾添加d
例如:staticClass.lib 改成staticClassd.lib,最后再把库文件夹的.h(其实也是定时器的.h)拷贝出来,总共3个文件
3、静态库使用
a)创建新的QMainwindow项目,ui界面中添加widget,将2个.lib文件放入同一个文件夹中
b)添加静态库
选择第一个即可,最后.pro新增如下
c).h
d).cpp
e)运行
三、共享库生成和隐式链接调用
四、共享库生成和显示链接调用
原文:https://www.cnblogs.com/GEEK-ZHAO/p/13975270.html