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. Import Header Files in the .pro file
QtWS25 Last Chance

Import Header Files in the .pro file

Scheduled Pinned Locked Moved Unsolved General and Desktop
c2491dllimportstaticdataheader
2 Posts 2 Posters 2.2k 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.
  • M Offline
    M Offline
    Michael.R.LegakoL-3com.com
    wrote on last edited by
    #1

    I've been bitten a couple of times now by a pretty subtle mistake that fortunately is quite easy to avoid. The issue occurs when you have a QT custom Widget of some sort that you want to share among different applications, and when you put the Custom Widget code in its own library. The mistake is to add the header for the Widget library to the HEADER list in the application. Doing this (for Windows applications) will cause the compilation of the application to fail with error C2491: '<WidgetLibraryName>::staticMetaObject' : definition of dllimport static data member not allowed. Instead, I've learned the correct thing to do is just make sure INCLUDEPATH has the correct paths so that the Widget Library's external header file(s) can be located. Now all that is fine, but it sure is handy to be able to see a list of those import library headers as part of my project, so my question is: bolded text Is there any QMAKE variable one can use to list import library header files upon which an application (or library) is dependent?

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @Michael-R-LegakoL-3com-com,

      I think a better approach, is to use a macro to apply the dllimport/export, and then enable that macro in the library only.

      For example, if you look at qmake's simple_dll test example, the simple.h header contains:

      #ifdef SIMPLEDLL_MAKEDLL
      # define SIMPLEDLL_EXPORT Q_DECL_EXPORT
      #else
      # define SIMPLEDLL_EXPORT Q_DECL_IMPORT
      #endif
      
      class SIMPLEDLL_EXPORT Simple
      {
      ...
      }
      

      Then the simple_dll.pro file contains:

      DEFINES	+= SIMPLEDLL_MAKEDLL
      

      So, this way, when the library is being built (via simple_dll.pro), then class is dllexport'ed. But when other code uses that same header (in doesn't define SIMPLEDLL_MAKEDLL) then that same class is dllimport'ed instead.

      Typically, you end up doing this sort of thing to many classes in a single library, so rather than having the #ifdef ... #define ... etc in each header file, it often ends up being written once in a "global" project header of some kind. For example, Q_CORE_EXPORT gets defined in qglobal.h, then used throughout all of the exported core Qt class headers.

      Also see:

      • When creating a library with Qt/Windows and using it in an application, then there is a link error regarding symbols which are in the library

      Cheers.

      1 Reply Last reply
      3

      • Login

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