How to solve error messages when converting a QMake .pro file to a CMake .txt file?
-
I have an old project named MotherVoice, which was written in Qt 5.14.0 several years ago. In preparation for upgrading to Qt 6, I downloaded Qt 5.15.2 and Qt Creator 14.0.1, and updated my scripts accordingly. The updated project worked properly in Qt 5.15.2.
However, I noticed that starting from Qt 6, CMake is going to be the main theme (instead of QMake). So, I watched a few YouTube videos and converted my Qt project file into a CMake file. For clarity, here is the CMakeLists.txt file that I created:
cmake_minimum_required(VERSION 3.14) project(MotherVoice VERSION 0.11) set(TARGET_NAME "MotherVoice") set(CMAKE_PREFIX_PATH "C:/Qt/5.15.2/mingw81_64") find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Charts Multimedia) add_executable(${TARGET_NAME} main.cpp mainwindow.cpp subjectwindow.cpp ../../FuhClasses/CWav.cpp ../../FuhClasses/FuhClasses.cpp ../../FuhClasses/dataMotherVoice.cpp ../../FuhClasses/recordMotherVoice.cpp ../../FuhClasses/entryMotherVoice.cpp ) target_sources(${TARGET_NAME} PRIVATE mainwindow.h subjectwindow.h ../../FuhClasses/CWav.h ../../FuhClasses/FuhClasses.h ../../FuhClasses/dataMotherVoice.h ../../FuhClasses/recordMotherVoice.h ../../FuhClasses/entryMotherVoice.h ../../../xResources/FFTReal/v2.00/Array.h ../../../xResources/FFTReal/v2.00/Array.hpp ../../../xResources/FFTReal/v2.00/def.h ../../../xResources/FFTReal/v2.00/DynArray.h ../../../xResources/FFTReal/v2.00/DynArray.hpp ../../../xResources/FFTReal/v2.00/FFTReal.h ../../../xResources/FFTReal/v2.00/FFTReal.hpp ../../../xResources/FFTReal/v2.00/FFTRealFixLen.h ../../../xResources/FFTReal/v2.00/FFTRealFixLen.hpp ../../../xResources/FFTReal/v2.00/FFTRealFixLenParam.h ../../../xResources/FFTReal/v2.00/FFTRealPassDirect.h ../../../xResources/FFTReal/v2.00/FFTRealPassDirect.hpp ../../../xResources/FFTReal/v2.00/FFTRealPassInverse.h ../../../xResources/FFTReal/v2.00/FFTRealPassInverse.hpp ../../../xResources/FFTReal/v2.00/FFTRealSelect.h ../../../xResources/FFTReal/v2.00/FFTRealSelect.hpp ../../../xResources/FFTReal/v2.00/FFTRealUseTrigo.h ../../../xResources/FFTReal/v2.00/FFTRealUseTrigo.hpp ../../../xResources/FFTReal/v2.00/OscSinCos.h ../../../xResources/FFTReal/v2.00/OscSinCos.hpp ) add_definitions(-DQT_DEPRECATED_WARNINGS) # This line makes the compiler to emit warnings if you use any feature of Qt which has been marked as deprecated (the exact warnings depend on your compiler). if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() qt5_add_resources(${TARGET_NAME} "MyResources" PREFIX "/FuhResources" FILES imageFiles/correct.png imageFiles/incorrect.png ) if(WIN32) set(WIN_ICON "../../../xResources/AEPLab_icon/AEP_logo_3D_original.ico") target_sources(${TARGET_NAME} PRIVATE ${WIN_ICON}) elseif(APPLE) # Add icon set for MacOS set(MAC_ICON "../../../xResources/AEPLab_icon/AEP_logo_3D.icns") set_source_files_properties(${MAC_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") target_sources(${TARGET_NAME} PRIVATE ${MAC_ICON}) endif() target_include_directories(${TARGET_NAME} PRIVATE ../../FuhClasses ../../../xResources/FFTReal/v2.00 ) target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Charts Qt5::Multimedia ) install(FILES ../../../xResources/AEPLab_icon/AEP_logo_3D_original.ico DESTINATION . )
For clarity, please allow me to explain a bit about this project/app. In this app, sounds recorded from either the listener's mother or a female stranger will play. After hearing a sound, the listener decides whether it was their mother by pressing a button on the display. In other words, this app contains two windows: MainWindow and SubjectWindow. The MainWindow is for the experimenter to enter parameters, while the SubjectWindow is for the participant to respond.
When configuring this project, the Qt Creator does not emit any error message for the CMake file that I just created. This is good. However, when I tried to build this project, I got many error messages. For clarity, here is a screenshot of the top portion of the list of the error messages:
The majority of the error messages said something like this: "Undefined reference to <name of a specific function>. It seemed to me that all these error messages are related to the "signal" functions. I mean, I used signal-and-slot connections to communicate between these two windows.
For clarity, here is the section where the "signal" functions are defined in the mainwindow.h:
signals: void soundPlaying(int index); void doneDataCollection(qreal threshold, qreal reactionTime, qint32 mainParameterIndex); void deliverFeedBackStatus(bool feedBack); void deliverAutoPlayStatus(bool autoPlay); void deliverSubCode(QString subCode); void deliverWavFileName(QString subCode);
Here is the section where the "signal" functions are defined in the subjectwindow.h:
signals: void subjectResponded(int response); void subjectWindowClosed();
I am kind of confident that the connections between these signals and corresponding slots are structured correctly, because these scripts worked smoothly with no problem when using a QMake .pro project file.
For some reason, when I switched from my original QMake .pro file to a CMake .txt file, Qt Creator gave me error messages.
I am just a self-taught hobbyist in Qt programming, and am unfamiliar to CMake. So, I apologize if these error messages are caused by something obvious.
Any comments or suggestions will be greatly appreciated!
-
Looks like MOC is not called, add
set(CMAKE_AUTOMOC ON)
, actually better adding all these 3 lines if you also have qrc or ui files.set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON)
@Bonnie WOW! It works like a charm. Thank you SO MUCH!!!
-
Looks like MOC is not called, add
set(CMAKE_AUTOMOC ON)
, actually better adding all these 3 lines if you also have qrc or ui files.set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON)
-
Looks like MOC is not called, add
set(CMAKE_AUTOMOC ON)
, actually better adding all these 3 lines if you also have qrc or ui files.set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON)
@Bonnie WOW! It works like a charm. Thank you SO MUCH!!!
-