Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt global header, Plugin/Library build process

Qt global header, Plugin/Library build process

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt globaldefinesimportexportheader
3 Posts 2 Posters 125 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qtpp
    wrote on 28 Feb 2025, 16:07 last edited by Qtpp
    #1

    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... :(

    C 1 Reply Last reply 28 Feb 2025, 16:29
    0
    • Q Qtpp
      28 Feb 2025, 16:07

      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... :(

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 Feb 2025, 16:29 last edited by Christian Ehrlicher
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Q 1 Reply Last reply 28 Feb 2025, 16:43
      1
      • C Christian Ehrlicher
        28 Feb 2025, 16:29

        @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.

        Q Offline
        Q Offline
        Qtpp
        wrote on 28 Feb 2025, 16:43 last edited by
        #3

        @Christian-Ehrlicher

        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

        1 Reply Last reply
        0

        2/3

        28 Feb 2025, 16:29

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved