[Qt-interest] Q_OBJECT in DLL - Release build warnings

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Tue Feb 9 10:04:54 CET 2010


Catalin Roman wrote on Monday, February 08, 2010 1:55 PM:

> Hello again,
> Unfortunately with the same problem, but now it appears in both
> Debug/Release build modes. As I stated earlier, all my defines are in
> place:  
> in foo.pro:
> DEFINES += FOO_LIBRARY
> 
> in foo_global.h:
> #if defined(FOO_LIBRARY)
> #  define FOOSHARED_EXPORT Q_DECL_EXPORT #else #  define
> FOOSHARED_EXPORT Q_DECL_IMPORT #endif 
> 
> in foo.h:
> class FOOSHARED_EXPORT myClass : public QObject{ Q_OBJECT;
> public:
> ...
> }
> 
> Is it possible that I'm missing some other Qt Creator setting? If so,
> which one? 

Your code snippet looks okay to me. Maybe there are some project settings in your Qt Creator environment which are wrong.

But just for my understanding, you are using Qt Creator + Visual Studio compiler, is that correct? Otherwise you wouldn't get these compiler warnings (this __declspec(dllexport/import) is a Visual Studio compiler thing only, I believe).

I have attached a small example: a library 'Foo' which exports certain methods only (as explained in my 2nd approach in my previous post) and an executable "Bar" which calls a method in 'Foo'. It also connects to some signal in 'Foo', as to show that the Q_OBJECT etc. generated code really works.

In the toplevel directory either do a

- qmake && mingw32-make (for the MinGW32 version) or
- open the Visual Studio solution *.sln (VS 2005 and above)

With Qt 4.6.0 (MinGW32 Qt SDK binary build) and Qt 4.6.1 (compiled with Visual Studio 2005 Express from source) it compiles fine without warnings (both MinGW32 gcc and Visual Studio 2005 Express compiler), as expected. Does it work for you? If so, "compare the settings" and apply the changes to your project ;)

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FooBar.zip
Type: application/x-zip-compressed
Size: 6587 bytes
Desc: FooBar.zip
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100209/ed7916a0/attachment.bin 


More information about the Qt-interest-old mailing list