C2491 Error using QT_INIT_METAOBJECT
-
Hello,
I am using Qt 5.13.2 (porting from Qt 4.8.2), CMAke 3.16.0-rc3, VS2017 and running into the following errors:
Severity Code Description Project File Line Error C2491 'SpinboxSlider::staticMetaObject': definition of dllimport static data member not allowed cust_widgets moc_SpinboxSlider.cpp 229
Offending code in moc_SpinboxSlider.cpp
QT_INIT_METAOBJECT const QMetaObject SpinboxSlider::staticMetaObject = { { &QWidget::staticMetaObject, qt_meta_stringdata_SpinboxSlider.data, qt_meta_data_SpinboxSlider, qt_static_metacall, qt_meta_extradata_SpinboxSlider, nullptr } };
-
Hi
I assume its not an old MOC file but newly generated. :)Is SpinboxSlider.cpp / h decorated with import/export or similar for being used
in a library? -
Yes, newly generated MOC. Here is the top of the header:
class QDESIGNER_WIDGET_EXPORT SpinboxSlider : public QWidget { Q_OBJECT Q_ENUMS( TickSetting ) Q_PROPERTY( int minValue READ minValue WRITE setMinValue ) Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) Q_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) Q_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) Q_PROPERTY( int value READ value WRITE setValue ) Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation ) Q_PROPERTY( int tickInterval READ tickInterval WRITE setTickInterval ) Q_PROPERTY( QString spinboxLabel READ spinboxLabel WRITE setSpinboxLabel ) Q_PROPERTY( QSlider::TickPosition tickmarks READ tickmarks WRITE setTickmarks )
Another important difference of note is that i'm now using CMake instead of QMake.
-
@DWayne said in C2491 Error using QT_INIT_METAOBJECT:
class QDESIGNER_WIDGET_EXPORT SpinboxSlider : public QWidget { Q_OBJECT
[more code]
QDESIGNER_WIDGET_EXPORT
is your problem. Why is this there and how it came to be?Another important difference of note is that i'm now using CMake instead of QMake.
Nope, it's unrelated to the build system. The error you get is from the link step.
-
Did you read the documentation I linked to ?
-
SGaist,
thanks for the article. I've replaced QDESIGNER_WIDGET_EXPORT with a CMake module that contains the following for use in targets that need to do exports:
cmake_minimum_required(VERSION 3.16) function(SetupWindowsDllLinkage target_name declspec_def) if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_compile_definitions(${target_name} PRIVATE "${declspec_def}=$<$<STREQUAL:$<TARGET_PROPERTY:${target_name},TYPE>,SHARED_LIBRARY>:__declspec(dllexport)>" INTERFACE "${declspec_def}=$<$<STREQUAL:$<TARGET_PROPERTY:${target_name},TYPE>,SHARED_LIBRARY>:__declspec(dllimport)>") else() target_compile_definitions(${target_name} PUBLIC "${declspec_def}=") endif() endfunction()