最新版本的obs,2017-03-20下载,moc文件是自动生成的,一开始完全懵逼了,之前都是自己手动用moc从.h生成,现在完全没找到哪里把自动生成的moc加入,研究了半天,总算搞明白怎么自动生成了:
1、在用cmake生成完工程后,在xxx-prj\UI\CMakeFiles\obs_automoc.dir下有一个AutogenInfo.cmake文件,这是由cmake为我们自动生成的:
set(AM_SOURCES "G:/obs-studio-masterv2/obs-studio-master/UI/platform-windows.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/win-update/update-window.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/win-update/win-update.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/win-update/win-update-helpers.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/obs-app.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/api-interface.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-filters.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-settings.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-interaction.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-properties.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-outputs.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-source-select.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-scene-collections.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-transitions.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-dropfiles.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-profiles.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-license-agreement.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-status-bar.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-adv-audio.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-transform.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-preview.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-namedialog.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-log-reply.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-projector.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-remux.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/properties-view.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/focus-list.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/menu-button.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/double-slider.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/volume-control.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/adv-audio-control.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/item-widget-helpers.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/visibility-checkbox.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/vertical-scroll-area.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/visibility-item-widget.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/slider-absoluteset-style.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/source-list-widget.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/qt-display.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/crash-report.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/hotkey-edit.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/source-label.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/remote-text.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/audio-encoders.cpp;G:/obs-studio-masterv2/obs-studio-master/UI/qt-wrappers.cpp" )
set(AM_RCC_SOURCES )
set(AM_RCC_INPUTS )
set(AM_SKIP_MOC "" )
set(AM_SKIP_UIC )
set(AM_HEADERS "G:/obs-studio-masterv2/obs-studio-master/UI/win-update/update-window.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/win-update/win-update.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/win-update/win-update-helpers.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/obs-app.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/platform.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-main.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-filters.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-settings.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-interaction.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-properties.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-main-outputs.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-source-select.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-license-agreement.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-status-bar.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-adv-audio.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-transform.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-basic-preview.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-namedialog.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-log-reply.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-projector.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/window-remux.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/properties-view.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/properties-view.moc.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/display-helpers.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/double-slider.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/focus-list.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/menu-button.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/mute-checkbox.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/volume-control.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/adv-audio-control.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/item-widget-helpers.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/visibility-checkbox.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/vertical-scroll-area.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/visibility-item-widget.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/slider-absoluteset-style.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/source-list-widget.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/qt-display.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/crash-report.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/hotkey-edit.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/source-label.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/remote-text.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/audio-encoders.hpp;G:/obs-studio-masterv2/obs-studio-master/UI/qt-wrappers.hpp" )
set(AM_MOC_COMPILE_DEFINITIONS "DL_D3D11=\"libobs-d3d11.dll\";DL_D3D9=\"\";DL_OPENGL=\"libobs-opengl.dll\";HAVE_OBSCONFIG_H;QT_CORE_LIB;QT_GUI_LIB;QT_NO_DEBUG;QT_WIDGETS_LIB;UNICODE;_CRT_SECURE_NO_WARNINGS;_UNICODE")
set(AM_MOC_INCLUDES "G:/obs-studio-masterv2/obs-studio-master/build-win32/UI;G:/obs-studio-masterv2/obs-studio-master/UI;G:/obs-studio-masterv2/obs-studio-master/UI/obs-frontend-api;G:/obs-studio-masterv2/obs-studio-master/libobs;G:/obs-studio-master/obs-studio-master/dependencies2013/win32/include;G:/obs-studio-masterv2/obs-studio-master/deps/blake2/src;G:/obs-studio-masterv2/obs-studio-master/build-win32/config;G:/obs-studio-masterv2/obs-studio-master/deps/libff/.;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/include;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/include/QtWidgets;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/include/QtGui;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/include/QtANGLE;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/include/QtCore;D:/Qt/Qt5.8.0-win32/5.8/msvc2013/./mkspecs/win32-msvc2013;G:/obs-studio-masterv2/obs-studio-master/deps/jansson/src;G:/obs-studio-masterv2/obs-studio-master/build-win32/deps/jansson/include")
set(AM_MOC_OPTIONS "")
set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "")
set(AM_CMAKE_BINARY_DIR "G:/obs-studio-masterv2/obs-studio-master/build-win32/")
set(AM_CMAKE_SOURCE_DIR "G:/obs-studio-masterv2/obs-studio-master/")
set(AM_QT_MOC_EXECUTABLE "D:/Qt/Qt5.8.0-win32/5.8/msvc2013/bin/moc.exe")
set(AM_QT_UIC_EXECUTABLE "")
set(AM_QT_RCC_EXECUTABLE "")
set(AM_CMAKE_CURRENT_SOURCE_DIR "G:/obs-studio-masterv2/obs-studio-master/UI/")
set(AM_CMAKE_CURRENT_BINARY_DIR "G:/obs-studio-masterv2/obs-studio-master/build-win32/UI/")
set(AM_QT_VERSION_MAJOR "5")
set(AM_TARGET_NAME "obs_automoc")
set(AM_ORIGIN_TARGET_NAME "obs")
set(AM_RELAXED_MODE "FALSE")
set(AM_UIC_TARGET_OPTIONS )
set(AM_UIC_OPTIONS_FILES )
set(AM_UIC_OPTIONS_OPTIONS )
set(AM_RCC_OPTIONS_FILES )
set(AM_RCC_OPTIONS_OPTIONS )
set(AM_MOC_COMPILE_DEFINITIONS_Debug "DL_D3D11=\"libobs-d3d11.dll\";DL_D3D9=\"\";DL_OPENGL=\"libobs-opengl.dll\";HAVE_OBSCONFIG_H;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;UNICODE;_CRT_SECURE_NO_WARNINGS;_UNICODE")
显而易见:AM_HEADERS 就是指定要扫描并自动生成moc文件的头文件;AM_SOURCES 就是自动生成MOC文件的;
2、我们在上面的文件中添加一个头文件:
#include
class CTestMoc : public QObject
{
Q_OBJECT
public:
CTestMoc(){}
~CTestMoc(){}
signals:
void Test1();
void Test2(int iTemp);
private slots:
void OnTest1();
void OnTest2(int iTemp);
};
3、重新编译obs工程,发现在obs_automoc.dir中生成了test_moc.xxxxxx.cpp;
但是工程编译提示缺少Test1,Test2的定义,没关系,这个我们在cpp中定义这个函数(和window-basic-main.cpp一样)就不会有问题了。
4、大功告成,后面就可以添加自己的界面程序到工程里面了哈哈。