user12071441
user12071441

Reputation: 115

using qt with adtf. Generation of moc file during build time?

I am trying to use qt with adtf 3.3 .

From the documentation of adtf (https://support.digitalwerk.net/adtf/v3/adtf_html/page_external_dependencies.html) and example from adtf using qt(https://support.digitalwerk.net/adtf/v3/adtf_html/page_demo_qt_video_display_code.html).

Brief intro about what i am trying to do.

I have created one ui file using QtDesigner and then i generated manually header file using uic compiler then also generated moc file since i have signal and slots functionality i also need moc file to call metaobjects.

So Now i would like to do is instead of generating manually header file using uic and moc file i wanted to generate moc file during build time using

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

the reason why i am doing like this if i change some functionality or added some signal and slots then i need to generate separatley and add in the sources file.

So basically my header file generated by uic contains info about objects used in qt form. Basically it translates xml file type which contains information about ui to header file using uic compiler.

#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

and then i have a moc file generated my moc compiler they are always generated for all QObject classes. They are absolutely required for meta stuff to work, so things like: signals for example.

My CMAKELists look like

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*/
    
    )

So my question is can i generate moc file in build time?

Since I am using adtf_use_qt(widgets) and in cmake gui i point out qt_dir then everything works fine. However i need to keep moc file in the sources.

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.

Please excuse me if my question is not clear.If you need any more info please ask i will try to elaborate in a much better way than this. Thanks

Upvotes: 0

Views: 177

Answers (1)

michaelharald1990
michaelharald1990

Reputation: 21

are you still having trouble creating your moc files? Maybe you only have to add your xxx.ui file to the filter sources. The ui_xxx.h could be included within your source files.

For example:

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)

Upvotes: 2

Related Questions