1. 程式人生 > >Qt5.6在vs2013中匯出Dll

Qt5.6在vs2013中匯出Dll

新建工程,選擇Qt Class Library,此項可以匯出類也可以匯出函式:


新建之後,在新建一個test專案用來呼叫Dll:


在HelloDll的標頭檔案中增加一個類成員函式和全域性函式

HelloDll.h

#pragma once

#include "hellodll_global.h"

class HELLODLL_EXPORT HelloDll
{
public:
	HelloDll();
	void DllClass();
};

int HELLODLL_EXPORT DllFunc();
HelloDll.cpp
#include "HelloDll.h"
#include <QMessageBox>

HelloDll::HelloDll()
{
}

void HelloDll::DllClass()
{
	QMessageBox::about(NULL, "Dll", "This is a class");
}

int DllFunc()
{
	QMessageBox::about(NULL, "Dll", "This is a function");
	return 0;
}

在test的介面中增加兩個按鈕,分別測試類成員函式和全域性函式

測試專案標頭檔案:

test.h

#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_test.h"

class test : public QMainWindow
{
	Q_OBJECT

public:
	test(QWidget *parent = Q_NULLPTR);

private:
	Ui::testClass ui;

public slots:
	void testDllClass();
	void testDllFunc();
};
test.cpp
#include "test.h"
#include "../HelloDll/HelloDll.h"

test::test(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
}

void test::testDllClass()
{
	HelloDll DLL;
	DLL.DllClass();

}

void test::testDllFunc()
{

	DllFunc();
}
測試效果圖