qt - How to compile the header file with Q_OBJECT macro in Xcode? -
i create c++ project in xcode links against qt framework. hello world program works well. when add class derived qobject , add q_objcet macro, there link error.
the class
myobject.h
#ifndef myobject_h #define myobject_h #include <qtcore/qobject> class myobject : public qobject { q_object public: myobject(); }; #endif
myobject.cpp
#include "myobject.h" myobject::myobject() { }
i know should use moc compile myobject.h first , add generated moc_myobject.cpp xcode project.
in microsoft visual studio, can configure header file compiled moc custom tool. , add generate cpp file vs project.
but xcode. question is: there equivalent mean in xcode compile header file including q_object macro?
here's how in xcode 6:
select target , in build rules make new custom rule. set "process" drop down "source files names matching" , type in *.h
next that. set "using" drop down "custom script:" , in script type close this:
/path/to/your/qt/bin/moc ${input_file_path} -o ${derived_file_dir}/${input_file_base}_moc.cpp
you'll have change path wherever moc executable is. set "output files" to:
${derived_file_dir}/${input_file_base}_moc.cpp
that's custom rule.
now headers compiled rule. while target still selected go "build phases". expand "compile sources" section, hit "+" button @ bottom. find , add header files q_object classes in them. add headers project first if can't find them in there.
that's it, xcode run moc on headers , understand output moc .cpp , needs compiled , linked app , you.
Comments
Post a Comment