T
T
Tesla4o2022-04-19 20:08:29
Qt
Tesla4o, 2022-04-19 20:08:29

How to work with Qt *.qrc file in CMake project?

Unable to get resource file in code.
wrote in CMake

set(SOURCES 
    main.cpp
    mainwindow.cpp
    mainwindow.ui
)

qt_add_resources(RSS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources.qrc)

add_executable(${PROJECT} ${SOURCES} ${RSS_SOURCES})


*.qrc file
<RCC>
    <qresource prefix="/">
        <file>resources/css/style.css</file>
    </qresource>
</RCC>


And in main.cpp I'm trying to get the file to load the style
QFile styleFile(":/resources/css/syle.css");

if (styleFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        auto f = styleFile.readAll();
        qDebug() << f;
        qApp->setStyleSheet(f);
        styleFile.close();
} else {
        qDebug() << styleFile.errorString();
}


As a result, it goes to the else branch with the message "File not found ..."
For the first time I am doing a project on CMake. Everything works fine in .pro.
Tell me what's wrong here?

PS
The style.css file certainly exists at the specified path.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory, 2022-04-19
@Tesla4o

If you create an empty QML project, then qml.qrc will be included in it. I'm not strong in CMAKE, so I just advise you to check it yourself and figure it out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question