使用qt和adtf.在构建期间生成moc文件



我正在尝试将qt与adtf 3.3一起使用。

来自adtf的文档(https://support.digitalwerk.net/adtf/v3/adtf_html/page_external_dependencies.html)以及adtf中使用qt的示例(https://support.digitalwerk.net/adtf/v3/adtf_html/page_demo_qt_video_display_code.html)。

关于我尝试做什么的简短介绍。

我已经使用QtDesigner创建了一个ui文件,然后我使用uic编译器手动生成了头文件,然后还生成了moc文件,因为我有信号和插槽功能,我还需要moc文件来调用元对象。

所以现在我想做的不是使用uic和moc文件手动生成头文件,而是在构建时使用生成moc文件

set(CMAKE_AUTOMOC_ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

我这样做的原因是,如果我更改了一些功能或添加了一些信号和插槽,那么我需要生成separatley并添加到源文件中。

所以基本上,我的uic生成的头文件包含了qt形式中使用的对象的信息。基本上,它使用uic编译器将包含ui信息的xml文件类型转换为头文件。

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/QWidget>
#include <QLineEdit>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
QGroupBox *groupBox_dummy;
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
//Form->resize(960, 480);
Form->setFixedSize(960, 480);
/*Contains several qobjects removed intentionally as it makes post so long*/

retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{

} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE

然后我有一个moc文件生成了我的moc编译器,它们总是为所有QObject类生成的。它们是元东西工作所绝对需要的,比如:信号。

我的CMAKELists看起来像

set (CMAKE_CXX_STANDARD 11)
include(FetchContent)
find_package(ADTF REQUIRED HINTS ${ADTF_DIR} COMPONENTS filtersdk ui)
adtf_use_qt(Widgets)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
find_package(Eigen3 CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/eigen/share/eigen3/cmake)
set(OpenCV_STATIC ON)
find_package(OpenCV CONFIG REQUIRED HINTS ${CMAKE_SOURCE_DIR}/libs/opencv)
# include directories
include_directories(inc)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${EIGEN3_INCLUDE_DIR})

# specify target
set(TARGET_NAME dummy)
set (TARGET_SOURCES
inc/uic_dummy.h->file generated by uic compiler. this code snipper is shown above
inc/dummy.h -> this basically contains several methods like createview and severalt hings and also slots (for qt functionality)
inc/stdafx.h -> contains all includes in this file
src/dummy.cpp->definitions of all the functions mentioned in dummy.h

src/moc_dummy.cpp-> moc file everytime i need to keep in the sources list. However i want to generate it in build time instead of saying like this uisng CMAKE_AUTOMOC ON
)

adtf_add_filter(${TARGET_NAME} ${TARGET_SOURCES})
target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Widgets ${OpenCV_LIBS} adtf::ui)
adtf_disable_qt_warnings(${TARGET_NAME})

adtf_install_target(${TARGET_NAME} ${CMAKE_INSTALL_PREFIX}/dummy/dummy)

adtf_create_plugindescription(
/*removed intentionall as it is not the area of the concern in this scenario*/

)

所以我的问题是,我可以在构建时生成moc文件吗?

由于我使用adtf_use_qt(小部件(,并且在cmakegui中我指出qt_dir,所以一切都很好。然而,我需要在源代码中保留moc文件。

Normally when i use qt withouf adtf i basicall use find_package(qt) and also use 
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE AUTORCC ON)
Then i will only keep my ui file in the sources and then it generates 
everyhting forme. Ideally i would like to know if i can do the same for adtf.

如果我的问题不清楚,请原谅。如果你需要更多的信息,请问我,我会尝试用一种比这更好的方式来阐述。感谢

您在创建moc文件时仍然遇到问题吗?也许您只需要将xxx.ui文件添加到过滤器源中。ui_xxx.h可以包含在源文件中。

例如:

set(PLUGIN_TARGETNAME your_filter)
adtf_add_filter(${PLUGIN_TARGETNAME}
${PLUGIN_TARGETNAME}.h
${PLUGIN_TARGETNAME}.cpp
${PLUGIN_TARGETNAME}.ui
)
target_link_libraries(${PLUGIN_TARGETNAME} PRIVATE
adtf::systemsdk
adtf::filtersdk
adtf::ui)
set_target_properties(${PLUGIN_TARGETNAME} PROPERTIES FOLDER src)
adtf_create_plugindescription(
TARGET  ${PLUGIN_TARGETNAME}
PLUGIN_SUBDIR "bin")
set_target_properties(${PLUGIN_TARGETNAME} 
PROPERTIES AUTOMOC ON AUTOUIC ON AUTOGEN_TARGET_DEPENDS ${PLUGIN_TARGETNAME}.ui)

最新更新