qt - Errors in generated MOC files for QT5 from cmake -


i generated moc files qt5 using

set (cmake_automoc on) set(cmake_include_current_dir on) 

then add moc files src using

set(src   src/main.cpp   src/video_widget_surface.cpp   src/video_widget.cpp   src/video_player.cpp #moc files   moc/moc_video_player.cpp   moc/moc_video_widget.cpp   moc/moc_video_widget_surface.cpp 

finally add executable using

add_executable(somegui ${src}) 

but errors in moc files saying :

/other/workspace/perception/somestuff/moc/moc_video_widget.cpp:54:6: error: 'videowidget' has not been declared /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:62:19: error: 'videowidget' has not been declared /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:68:20: error: 'videowidget' has not been declared /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:68:46: error: non-member function 'const qmetaobject* metaobject()' cannot have cv-qualifier /other/qt5.0.1/5.0.1/gcc_64/include/qtcore/qobject.h: in function 'const qmetaobject* metaobject()': /other/qt5.0.1/5.0.1/gcc_64/include/qtcore/qobject.h:401:33: error: 'qscopedpointer<qobjectdata> qobject::d_ptr' protected /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:70:21: error: within context /other/qt5.0.1/5.0.1/gcc_64/include/qtcore/qobject.h:401:33: error: invalid use of non-static data member 'qobject::d_ptr' /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:70:21: error: location /other/qt5.0.1/5.0.1/gcc_64/include/qtcore/qobject.h:401:33: error: 'qscopedpointer<qobjectdata> qobject::d_ptr' protected /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:70:50: error: within context /other/qt5.0.1/5.0.1/gcc_64/include/qtcore/qobject.h:401:33: error: invalid use of non-static data member 'qobject::d_ptr' /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:70:50: error: location /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: @ global scope: /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:73:7: error: 'videowidget' has not been declared /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: in function 'void* qt_metacast(const char*)': /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:47: error: expected type-specifier before 'videowidget' /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:47: error: expected '>' before 'videowidget' /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:47: error: expected '(' before 'videowidget' /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:47: error: 'videowidget' not declared in scope /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:59: error: expected primary-expression before '>' token /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:61: error: invalid use of 'this' in non-member function /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:77:67: error: expected ')' before ';' token /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:78:40: error: cannot call member function 'virtual void* qwidget::qt_metacast(const char*)' without object /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: @ global scope: /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:81:5: error: 'videowidget' has not been declared /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: in function 'int qt_metacall(qmetaobject::call, int, void**)': /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:83:43: error: cannot call member function 'virtual int qwidget::qt_metacall(qmetaobject::call, int, void**)' without object /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: in function 'void* qt_metacast(const char*)': /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:79:1: warning: control reaches end of non-void function [-wreturn-type] /other/workspace/perception/somestuff/moc/moc_video_widget.cpp: in function 'const qmetaobject* metaobject()': /other/workspace/perception/somestuff/moc/moc_video_widget.cpp:71:1: warning: control reaches end of non-void function [-wreturn-type] make[2]: *** [cmakefiles/somestuff.dir/moc/moc_video_widget.cpp.o] error 1 make[1]: *** [cmakefiles/somestuff.dir/all] error 2 make: *** [all] error 2 

my understanding there error in moc files created. don't have control on how created. how solve bug ?

cmake documentation not bad, not neglect reading it. misunderstood concept of automoc:

automoc boolean specifying whether cmake handle qt moc preprocessor automatically, i.e. without having use qt4_wrap_cpp() macro. qt4 supported. when property set true, cmake scan source files @ build time , invoke moc accordingly. if #include statement #include "moc_foo.cpp" found, q_object class declaration expected in header, , moc run on header file. if #include statement #include "foo.moc" found, q_object expected in current source file , moc run on file itself. additionally, header files parsed q_object macros, , if found, moc executed on files.

so, first of all, should not add generated moc files explicitly sources , push them executable compilation. in other words, push sources:

set(src   src/main.cpp   src/video_widget_surface.cpp   src/video_widget.cpp   src/video_player.cpp) 

and moc ones handled automatically cmake.

secondly, stated in documentation:

  • if q_object in foo.h (i.e. qobject declared in header file), in corresponding foo.cpp don't forget add #include "moc_foo.cpp", preferably @ end of file;

  • if q_object in foo.cpp (i.e. qobject declared in source file), then, again, in foo.cpp don't forget add #include "foo.moc", preferably @ end of file.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -