CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
string(REGEX REPLACE "[^a-zA-Z0-9_]" "" ProjectId ${ProjectId})
project(${ProjectId})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(Qt6 REQUIRED COMPONENTS Core Quick QmlWorkerScript)
qt_standard_project_setup()
set(CMAKE_CXX_CLANG_TIDY "clang-tidy-18")
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
qt_add_executable(${ProjectId} ${SRC_DIR}/main.cpp)
qt_add_qml_module(${ProjectId}
URI project
VERSION 1.0
QML_FILES
qml/Main.qml
SOURCES ${INCLUDE_DIR}/header.h
)
target_include_directories(${ProjectId} PUBLIC ${INCLUDE_DIR})
target_link_libraries(${ProjectId} PRIVATE Qt6::Core Qt6::Quick Qt6::QmlWorkerScript)
include(GNUInstallDirs)
install(TARGETS ${ProjectId}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
main.cpp
(where errors occur)
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "header.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:project/qml/Main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
Errors example: identifier "QGuiApplication" is undefined
;
incomplete type "QObject" is not allowed
;
incomplete type "const QUrl" is not allowed
;
no instance of function template "QtPrivate::qMakeStringPrivate" matches the argument list
;
name followed by '::' must be a class or namespace name
.
BUT everything compiles and builds fine.
Project is built in the Docker container. Qt packages I get:
qt6-base-dev
qt6-base-dev-tools
qt6-declarative-dev
qt6-declarative-dev-tools
qt6-httpserver-dev
qt6-qmllint-plugins
libqt6quickcontrols2-6
I tried using target_include_directories
explicitly, but problem remained the same. I’m not sure but it looks like error for QGuiApplication disappears when I visit source files of types that cause errors, but everything comes back as it was when I close those files.
Vitali Bakhanovich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.