Issue
I created a small test project to show my problem:
main.cpp
#include <QApplication>
#include <QPushButton>
int main(int argc, char* argv[]) {
QApplication a(argc, argv);
QPushButton button(QApplication::tr("Hello, World!"), nullptr);
button.resize(200, 100);
button.show();
return QApplication::exec();
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.27)
set(CMAKE_CXX_STANDARD 23)
project(TestQtWidgetsProject)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
add_executable(TestQtWidgetsProject main.cpp)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
target_link_libraries(TestQtWidgetsProject Qt::Core Qt::Gui Qt::Widgets)
find_package(Qt6 REQUIRED LinguistTools)
qt_create_translation(QM_FILES ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/translation_ru.ts)
I also created an empty file translation_ru.ts
in the project root directory.
But after building the project the file translation_ru.ts
remains empty and no .qm file is created in ${CMAKE_BINARY_DIR}
. Why?
Solution
I still haven't figured out why this code doesn't work, but as Alan Birtles said, the command is deprecated, so that might be the reason.
Here is a working code example for this project:
find_package(Qt6 REQUIRED LinguistTools)
qt_add_translations(TestQtWidgetsProject
INCLUDE_DIRECTORIES
${PROJECT_SOURCE_DIR}
TS_FILES
translation_ru.ts)
add_dependencies(TestQtWidgetsProject update_translations)
Answered By - AvidCoder Answer Checked By - Robin (WPSolving Admin)