Creating Custom QT Library

 ̄綄美尐妖づ 提交于 2019-12-11 22:27:08

问题


I created a static Qt library by using VS2005.

It created an extra file "test_global.h" besides expected ones(test.h and test.cpp).

test_global.h

#ifndef TEST_GLOBAL_H
#define TEST_GLOBAL_H

#include <Qt/qglobal.h>

#ifdef TEST_LIB
# define TEST_EXPORT Q_DECL_EXPORT
#else
# define TEST_EXPORT Q_DECL_IMPORT
#endif

#endif // TEST_GLOBAL_H

Why this file is generated, how I suppose to use it?

Thanks.


回答1:


You mark your class (or methods) as exported in your library headers:

class TEST_EXPORT TestClass {
    // ...
};

Then in your library pro file you add:

DEFINES += TEST_LIB

So during the dll compilation your class header will have "Q_DECL_EXPORT" macro which is Qt way to tell the linker "export this class/method", and when you use your dll in some application, the header will have "Q_DECL_IMPORT" macro.

For more information, check the Qt documentation.



来源:https://stackoverflow.com/questions/2763259/creating-custom-qt-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!