Qt global header, Plugin/Library build process
-
Hello guys,
might be a quite usual question, but since I'm working on a QtWidget Plugin (Widget-Library)
and was looking at the Qt Source how the Qt Widgets are built themselves, this question came up:The "How-to"-QWidget-Library guide mentions the Q_EXPORT macro that should be added to every shared QWidget class/library.
To manage the its proper IMPORT/EXPORT along the project config, a "foo_global.h" is recommended which is then included in every header of the library.
So far, so good. My yet simple shared QWidget library works and can be loaded as expected...Then I got intrigued and curious how the standard QWidgets (QtBase/QtWidget.dll) are configured, because I've never come across such "global" file which defines the macros for library EXPORT / IMPORT when using Qt.
When building the QtBase module from source I found a "qwidgetsglobal.h" in "QtBase/src/widgets/kernel/", however this file
does not contain the expected imports, but just another bunch of includes like:#include <QtWidgets/qtwidgets-config.h> #include <QtWidgets/qtwidgetsexports.h>
The "qtwidget-config.h" defines and enables all the single classes (referred to as "features") of the QtWidget library while
the "qtwidgetexports.h" finally contains the bits of code I was looking for...
Namely#if defined(QT_SHARED) || !defined(QT_STATIC) # if defined(QT_BUILD_WIDGETS_LIB) # define Q_WIDGETS_EXPORT Q_DECL_EXPORT # else # define Q_WIDGETS_EXPORT Q_DECL_IMPORT # endif #else # define Q_WIDGETS_EXPORT #endif
Exactly the macro which is used for every QWidget class in QtWidget library:
class Q_WIDGETS_EXPORT QPushButton : public QAbstractButton
But this file does not exist in the source directory... it's only in my build folder after building Qt...
So this file must the generated from some template or other source?!How does this work?
This is not about Qt directly... more that I am trying to undertstand the concept behind all this.
(How the QtWidget library is configured when files, that - I would suspect - needed for the build process, are not preset at first)
As also the Qt Documentation mentions the nessecarity of your own "foo_global.h" file as a convenient way to manage the imports of your custom shared QWidget library/plugin.I know this is really not the typical question on Qt for this user forum here, but if any Qt Dev or Qt Contributor with in-depth knowlegde could point me in the right direction, I highly appreciate it ^.^
By the way: I tried to find the place where said file originates from, but I got lost in between the hundreds ".cmake" and config files with dozens of CMake macros and functions... :(
-
@Qtpp said in Qt global header, Plugin/Library build process:
So this file must the generated from some template or other source?!
How does this work?
I would guess somehwere GenerateExportHeader cmake macro is getting called.
-
Oh well, did not expect the solution to be that simple (if this is actually the case)
Understanding the Qt Framework's library/module design is pain :D