Results 1 to 4 of 4

Thread: error definition of static member '...' of dllimport class

  1. #1
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default error definition of static member '...' of dllimport class

    I have ported my app to Qt4 and I am in the process of testing my build on Windows (I primarily work on Linux) and I am receiving errors that look like this:

    build\win32\libqtlcmswidgets\moc_lprofgauge.cc:81: error: definition of static data member 'LProfGauge::staticMetaObject' of dllimport'd class
    As you can see it is complaining about something in a moc file being declared as - well I am not sure what this means. The object is question is a custom widget that is in a static library (not in a DLL) and it appears that moc is generating incorrect code that the compiler is chocking on.

    This same static library contains other custom widgets (6 in total) and all of the hand written code for the custom widgets it compiling without any error messages. But the build fails when it tries to build the first moc generated code.

    I am using MinGW. I have found a few other threads that that touch on this type of error message but in every case it was someone asking how to get a specific application or library to build and being told by the author of that app or library to set something that was very specific to that app or library. So that info was not very helpful for me to understand what this is about and how to fix it. So could someone here point me to a source that explains in general what is causing this error and perhaps how to fix it?
    Last edited by jacek; 19th February 2008 at 02:03. Reason: changed [code] to [quote]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error definition of static member '...' of dllimport class

    Do you have anything between class and LProfGauge in LProfGauge's header file?

  3. #3
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error definition of static member '...' of dllimport class

    Since it is a custom widget it is defined as:

    Qt Code:
    1. class QDESIGNER_WIDGET_EXPORT LProfGauge : public QWidget
    To copy to clipboard, switch view to plain text mode 

    To test this I changed it to:

    Qt Code:
    1. class LProfGauge : public QWidget
    To copy to clipboard, switch view to plain text mode 

    and it got passed that error. It looks like the compile now works and I am having issues with the linker not finding the Qt libraries which should not be too hard to sort out.

    But I would still like to understand what is going on with this. Do I need to define something for the Windows build so that QDESIGNER_WIDGET_EXPORT does not cause a problem on Windows? All of my other widgets predated Qt4 and were ported to Qt4 and these do not have QDESIGNER_WIDGET_EXPORT. But this particular widget was derived from another source and it had QDESIGNER_WIDGET_EXPORT in the declaration for the widget and I left it in since it seemed to work and did not cause any issues on Linux.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error definition of static member '...' of dllimport class

    Quote Originally Posted by hvengel View Post
    Do I need to define something for the Windows build so that QDESIGNER_WIDGET_EXPORT does not cause a problem on Windows?
    This macro is required only for windows' DLLs. It should be empty for static libraries and other systems.

    So you need something like this:
    Qt Code:
    1. #ifdef STATIC_BUILD
    2. # define MY_WIDGET_EXPORT
    3. #else
    4. # define MY_WIDGET_EXPORT QDESIGNER_WIDGET_EXPORT
    5. #endif
    To copy to clipboard, switch view to plain text mode 
    (of course you will have to define STATIC_BUILD somehow).

    It's because QDESIGNER_WIDGET_EXPORT is meant for designer plugins and you don't link them statically.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 11:12
  2. static member initialization
    By high_flyer in forum General Programming
    Replies: 2
    Last Post: 17th September 2007, 22:22
  3. Replies: 2
    Last Post: 16th March 2007, 10:04
  4. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 11:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.