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. QDESIGNER_WIDGET_EXPORT in NON plugin/library projects
Forum Updated to NodeBB v4.3 + New Features

QDESIGNER_WIDGET_EXPORT in NON plugin/library projects

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 305 Views 1 Watching
  • 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.
  • DragoonD Offline
    DragoonD Offline
    Dragoon
    wrote on last edited by Dragoon
    #1

    Re: QDESIGNER_WIDGET_EXPORT macro usage

    If I code a custom widget and related plugin but I opt to use the widget trough an include directive (pointing to .pri) on Windows systems usagee of class decoration QDESIGNER_WIDGET_EXPORT causes compiling errors. Removing such macro will prevent compilation errors but will render widget plugin unusable.

    The problem is how to insert the macro only when compiling plugin and remove it when compiling the widget class for other purposes (i.e. using the widget code instead its library).

    I did it this way and it seems to work but I don't like this approach very much:

    In the plugin .pro file I put this:

    DEFINES     += QDESIGNER_PLUGIN=QDESIGNER_WIDGET_EXPORT
    

    Of course in the class I use this:

    class QDESIGNER_PLUGIN QVirtualPad : public QWidget
    

    In every other .pro file I need to put:

    DEFINES     += QDESIGNER_PLUGIN=''
    

    There's a better approach?

    bye by[t]e{s}... Mike

    Christian EhrlicherC 1 Reply Last reply
    0
    • DragoonD Dragoon

      Re: QDESIGNER_WIDGET_EXPORT macro usage

      If I code a custom widget and related plugin but I opt to use the widget trough an include directive (pointing to .pri) on Windows systems usagee of class decoration QDESIGNER_WIDGET_EXPORT causes compiling errors. Removing such macro will prevent compilation errors but will render widget plugin unusable.

      The problem is how to insert the macro only when compiling plugin and remove it when compiling the widget class for other purposes (i.e. using the widget code instead its library).

      I did it this way and it seems to work but I don't like this approach very much:

      In the plugin .pro file I put this:

      DEFINES     += QDESIGNER_PLUGIN=QDESIGNER_WIDGET_EXPORT
      

      Of course in the class I use this:

      class QDESIGNER_PLUGIN QVirtualPad : public QWidget
      

      In every other .pro file I need to put:

      DEFINES     += QDESIGNER_PLUGIN=''
      

      There's a better approach?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There is no need to use this predefined macro but you can use an own the same way it's done for every other shared library as explained here. Then there is no need to define something when you use the library.

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

      DragoonD 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        There is no need to use this predefined macro but you can use an own the same way it's done for every other shared library as explained here. Then there is no need to define something when you use the library.

        DragoonD Offline
        DragoonD Offline
        Dragoon
        wrote on last edited by Dragoon
        #3

        @Christian-Ehrlicher said in QDESIGNER_WIDGET_EXPORT in NON plugin/library projects:

        There is no need to use this predefined macro but you can use an own the same way it's done for every other shared library as explained here. Then there is no need to define something when you use the library.

        Are you sure that the widget compiled without the predefined macro will be usable both on Windows and Linux? Because official Qt docs states here that you should use such macro.

        In my experience widgets classes need such macro to be usable as a QtCreator plugin but maybe I'm wrong.

        Anyway in my specific case I use my widget both as a precompiled library and as an include subproject in such a case QDESIGNER_WIDGET_EXPORT macro (on Windows systems) lead to compilation error and must be removed from widget class source.
        Since I don't want to edit the class source every time I need to use it I need to find a different approach.

        The approach used in the link you referenced doesn't seem to work for my case since it compiles correctly in case:

        DEFINES += MYSHAREDLIB_LIBRARY
        

        is present, but doesn't compile at all if it's not.. the error is something like that (repeated for every class method):

        warning C4273: 'CustomWidget::CustomWidget': inconsistent dll link
        

        To make it work I need to do something like that:

        #if defined(MYSHAREDLIB_LIBRARY)
        #  define QDESIGNER_WIDGET_EXPORT Q_DECL_EXPORT
        #else
        #  define QDESIGNER_WIDGET_EXPORT
        #endif
        

        That of course will lead to some "macro redefinition warning".

        bye by[t]e{s}... Mike

        1 Reply Last reply
        0

        • Login

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