QDESIGNER_WIDGET_EXPORT in NON plugin/library projects
-
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?
-
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?
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.
-
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.
@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".