Results 1 to 9 of 9

Thread: AnalogClock::staticMetaObject': definition of dllimport static data member not allowe

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default AnalogClock::staticMetaObject': definition of dllimport static data member not allowe

    I'm using Qt 6.4.3 and took the example of the analog clock customwidgetplugin included in the Qt installation package. I compiled the plugin and placed it in the path C:\Qt\Tools\QtCreator\bin\plugins\designer. I create a new qt project based on QWidget. In its .ui form I select and insert the created plugin. So far, so good. When I compile the plugin test program, I get this error message:

    Qt Code:
    1. D:\dev\Qt\ProvaEsempioPlugin\debug\moc_analogclock.cpp:59: error: C2491: 'AnalogClock::staticMetaObject': definition of dllimport static data member not allowed
    To copy to clipboard, switch view to plain text mode 

    I don't understand where is the problem... You can help me ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: AnalogClock::staticMetaObject': definition of dllimport static data member not al

    Google is your friend here.

    Either you are building the plugin with the wrong dllimport / dllexport declaration or you are trying to use it in a program with the wrong declaration. You use dllexport when you are building the DLL and use dllimport when your are using the DLL in a program.

    And in Microsoft world, you cannot mix debug and release mode code. If the DLL was built in release mode to use with Qt Designer, you cannot link with that same release mode DLL if you are building a debug mode program. You must build a debug mode DLL to link with your debug mode program.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: AnalogClock::staticMetaObject': definition of dllimport static data member not al

    d_stranz
    No, the test project (like the plugin itself) are Release. I am attaching the .pro file of the test:
    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. CONFIG += c++17
    6.  
    7. # You can make your code fail to compile if it uses deprecated APIs.
    8. # In order to do so, uncomment the following line.
    9. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    10.  
    11. SOURCES += \
    12. main.cpp \
    13. widget.cpp
    14.  
    15. HEADERS += \
    16. widget.h \
    17. analogclock.h
    18.  
    19. FORMS += \
    20. widget.ui
    To copy to clipboard, switch view to plain text mode 
    If it can be useful, I also put the .pro of the plugin:
    Qt Code:
    1. QT += widgets uiplugin
    2.  
    3. QTDIR_build {
    4. # This is only for the Qt build. Do not use externally. We mean it.
    5. PLUGIN_TYPE = designer
    6. PLUGIN_CLASS_NAME = AnalogClockPlugin
    7. load(qt_plugin)
    8. CONFIG += install_ok
    9. } else {
    10. # Public example:
    11.  
    12. CONFIG += plugin
    13. TEMPLATE = lib
    14.  
    15. TARGET = $$qtLibraryTarget($$TARGET)
    16.  
    17. target.path = $$[QT_INSTALL_PLUGINS]/designer
    18. INSTALLS += target
    19. }
    20.  
    21. HEADERS = analogclock.h \
    22. customwidgetplugin.h
    23.  
    24. SOURCES = analogclock.cpp \
    25. customwidgetplugin.cpp
    To copy to clipboard, switch view to plain text mode 

    Where do I find the reference of dllimport in Qt code ? Please note that here I'm doing everything only in Qt environment, including IDE, for the moment I don't use Visual Studio C++ (here the same plugin project works fine, including the test program).
    I want to be able to make everything work in Qt environment, so I can finally verify the old QLed problem that you will remember well :-))
    Last edited by giorgik; 20th May 2023 at 18:27. Reason: updated contents

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: AnalogClock::staticMetaObject': definition of dllimport static data member not al

    No, the test project (like the plugin itself) are Release.
    Then why does your original post say this?

    D:\dev\Qt\ProvaEsempioPlugin\debug\moc_analogclock.cpp:59: error: C2491

    Anyway, the error is because you are including the header file "analogclock.h" as part of the HEADERS section in your .pro file. This causes Qt to create the moc_analogclock.cpp and try to compile it. But that file has already been compiled and is in your plugin DLL. So the compiler is complaining that you have defined the same static variable in two different places, your DLL and your application. Just remove the "analogclock.h" line from your .pro file. You are using the header, not building it.

    Where do I find the reference of dllimport in Qt code ?
    The header analogclock.h decalares the AnalogClock class this way:

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

    The macro QDESIGNER_WIDGET_EXPORT expands to:

    Qt Code:
    1. // qdesignerexportwidget.h
    2.  
    3. #if defined(QDESIGNER_EXPORT_WIDGETS)
    4. # define QDESIGNER_WIDGET_EXPORT Q_DECL_EXPORT
    5. #else
    6. # define QDESIGNER_WIDGET_EXPORT Q_DECL_IMPORT
    7. #endif
    To copy to clipboard, switch view to plain text mode 

    and Q_DECL_IMPORT and Q_DECL_EXPORT expand to:

    Qt Code:
    1. // qcompilerdetection.h
    2.  
    3. # define Q_DECL_EXPORT __declspec(dllexport)
    4. # define Q_DECL_IMPORT __declspec(dllimport)
    To copy to clipboard, switch view to plain text mode 

    The .pro file for the plugin causes QDESIGNER_EXPORT_WIDGETS to be defined for the plugin build, probably by some combination of the QTDIR_build section and CONFIG += plugin and TEMPLATE = lib declarations.

    If you are going to try to build a Qt Designer plugin in a Visual Studio project, then you need to add QDESIGNER_EXPORT_WIDGETS as a Preprocessor Definition in the C/C++ -> Preprocessor section of your plugin project Properties. That means the __declspec( dllexport ) declaration is active and causes the compiler to export the AnalogClock class from the DLL so you can use it in projects.

    When you are using the plugin in an application project, you do not use this define. If QDESIGNER_EXPORT_WIDGETS is not defined, then the __declspec( dllimport ) declaration is active and your class is imported from the DLL.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 3
    Last Post: 21st November 2017, 11:48
  2. Replies: 2
    Last Post: 10th October 2014, 09:49
  3. Replies: 2
    Last Post: 20th October 2011, 15:14
  4. Replies: 22
    Last Post: 8th October 2008, 13:54
  5. Replies: 3
    Last Post: 19th February 2008, 13:10

Tags for this Thread

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.