Не удается загрузить файл qml в проект qt на основе cmake

Я работаю над проектом Qt, основанным на cmake. Версия Qt — 5.7, Ubuntu 14.04. Я получаю ошибку:

QQmlApplicationEngine failed to load component
qrc:/main.qml:-1 File not found

CMakeLists.txt это:

file(GLOB_RECURSE UI_FILES *.ui)
file(GLOB_RECURSE CODE_FILES *.cpp *.h)

qt5_wrap_ui(UI_HEADERS ${UI_FILES})
qt5_add_resources(RESOURCE_FILES ../resources/resources.qrc)

set(SOURCES
assets/assets.qrc
icons/icons.qrc
qml/qml.qrc)

include(../vendor/CMakeLists.txt)

if (WIN32)
set(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj)
if (MSVC)
add_custom_command(OUTPUT ${WINDOWS_RES_FILE}
COMMAND rc.exe /fo ${WINDOWS_RES_FILE} resources.rc
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/win
)
else()
add_custom_command(OUTPUT ${WINDOWS_RES_FILE}
COMMAND windres.exe resources.rc ${WINDOWS_RES_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/win
)
endif()
endif()

add_executable(${CMAKE_PROJECT_NAME}
${SOURCES}
${UI_HEADERS}
${CODE_FILES}
${RESOURCE_FILES}
${WINDOWS_RES_FILE}
${VENDOR_SOURCES}
)

target_link_libraries(${CMAKE_PROJECT_NAME}
Qt5::Core
Qt5::Qml
Qt5::Quick
Qt5::Concurrent
Qt5::Widgets)

find_package( PythonLibs 2.7 REQUIRED )
include_directories( ${PYTHON_INCLUDE_DIRS} )

find_package( Boost COMPONENTS python REQUIRED )
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

target_link_libraries(${CMAKE_PROJECT_NAME}
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
${SWORD_LIBRARIES})

include_directories(${SWORD_INCLUDE_DIRS})

set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/data/Info.plist)

if (UNIX)
install(TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin)
elseif (WIN32)
install(TARGETS ${CMAKE_PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

Дерево вывода проекта:

.
|-- build
|   |-- CMakeCache.txt
|   |-- CMakeFiles
|   |   |-- 3.6.0-rc4
|   |   |   |-- CMakeCCompiler.cmake
|   |   |   |-- CMakeCXXCompiler.cmake
|   |   |   |-- CMakeDetermineCompilerABI_C.bin
|   |   |   |-- CMakeDetermineCompilerABI_CXX.bin
|   |   |   |-- CMakeSystem.cmake
|   |   |   |-- CompilerIdC
|   |   |   |   |-- a.out
|   |   |   |   `-- CMakeCCompilerId.c
|   |   |   `-- CompilerIdCXX
|   |   |       |-- a.out
|   |   |       `-- CMakeCXXCompilerId.cpp
|   |   |-- cmake.check_cache
|   |   |-- CMakeDirectoryInformation.cmake
|   |   |-- CMakeOutput.log
|   |   |-- CMakeRuleHashes.txt
|   |   |-- CMakeTmp
|   |   |-- feature_tests.bin
|   |   |-- feature_tests.c
|   |   |-- feature_tests.cxx
|   |   |-- Makefile2
|   |   |-- Makefile.cmake
|   |   |-- Progress
|   |   |   |-- 1
|   |   |   |-- 11
|   |   |   |-- 2
|   |   |   |-- 3
|   |   |   `-- count.txt
|   |   |-- progress.marks
|   |   |-- TargetDirectories.txt
|   |   `-- uninstall.dir
|   |       |-- build.make
|   |       |-- cmake_clean.cmake
|   |       |-- DependInfo.cmake
|   |       `-- progress.make
|   |-- cmake_install.cmake
|   |-- CTestTestfile.cmake
|   |-- ecm_uninstall.cmake
|   |-- Makefile
|   |-- source
|   |   |-- __
|   |   |   `-- resources
|   |   |       `-- resources.qrc.depends
|   |   |-- CMakeFiles
|   |   |   |-- CMakeDirectoryInformation.cmake
|   |   |   |-- progress.marks
|   |   |   |-- tutifruti_automoc.dir
|   |   |   |   |-- AutogenInfo.cmake
|   |   |   |   |-- AutomocOldMocDefinitions.cmake
|   |   |   |   |-- build.make
|   |   |   |   |-- cmake_clean.cmake
|   |   |   |   |-- DependInfo.cmake
|   |   |   |   |-- depend.internal
|   |   |   |   |-- depend.make
|   |   |   |   `-- progress.make
|   |   |   `-- tutifruti.dir
|   |   |       |-- __
|   |   |       |   `-- vendor
|   |   |       |       `-- material
|   |   |       |           `-- src
|   |   |       |               `-- core
|   |   |       |-- build.make
|   |   |       |-- cmake_clean.cmake
|   |   |       |-- CXX.includecache
|   |   |       |-- DependInfo.cmake
|   |   |       |-- depend.internal
|   |   |       |-- depend.make
|   |   |       |-- flags.make
|   |   |       |-- link.txt
|   |   |       `-- progress.make
|   |   |-- cmake_install.cmake
|   |   |-- CTestTestfile.cmake
|   |   |-- defines.h
|   |   |-- Makefile
|   |   |-- moc_main_window.cpp
|   |   |-- qrc_resources.cpp
|   |   |-- tutifruti_automoc.cpp
|   |   |-- tutifruti_automoc.dir
|   |   |   `-- vendor
|   |   |       `-- material
|   |   |           `-- src
|   |   |               |-- core
|   |   |               |   |-- moc_device.cpp
|   |   |               |   `-- moc_units.cpp
|   |   |               `-- moc_plugin.cpp
|   |   `-- ui_main_window.h
|   `-- tests
|       |-- CMakeFiles
|       |   |-- CMakeDirectoryInformation.cmake
|       |   `-- progress.marks
|       |-- cmake_install.cmake
|       |-- CTestTestfile.cmake
|       |-- defines.h
|       `-- Makefile
|-- cmake
|   |-- FindCaffe.cmake
|   |-- FindSWORD.cmake
|   `-- LibFindMacros.cmake
|-- CMakeLists.txt
|-- CMakeLists.txt.user
|-- LICENCE
|-- Licence.rtf
|-- README.md
|-- resources
|   |-- icons
|   |   |-- action_home.svg
|   |   |-- action_list.svg
|   |   |-- action_search.svg
|   |   |-- action_settings.svg
|   |   |-- file_cloud_done.svg
|   |   |-- icons.qrc
|   |   |-- maps_place.svg
|   |   |-- navigation_check.svg
|   |   `-- social_school.svg
|   `-- resources.qrc
|-- source
|   |-- assets
|   |   |-- assets.qrc
|   |   |-- book-open-page.svg
|   |   `-- book-open.svg
|   |-- backend
|   |   |-- biblechapter.cpp
|   |   |-- biblechapter.h
|   |   |-- bible.cpp
|   |   |-- bible.h
|   |   |-- biblemanager.cpp
|   |   |-- biblemanager.h
|   |   |-- CMakeLists.txt
|   |   |-- module.cpp
|   |   |-- module.h
|   |   |-- plugin.cpp
|   |   |-- progress.h
|   |   `-- promise.h
|   |-- CMakeLists.txt
|   |-- cpp
|   |-- icons
|   |   |-- action_home.svg
|   |   |-- action_list.svg
|   |   |-- action_search.svg
|   |   |-- action_settings.svg
|   |   |-- file_cloud_done.svg
|   |   |-- icons.qrc
|   |   |-- maps_place.svg
|   |   |-- navigation_check.svg
|   |   `-- social_school.svg
|   |-- icons.yml
|   |-- main.cpp
|   |-- python
|   |   |-- data
|   |   |   |-- external
|   |   |   |-- interim
|   |   |   |-- processed
|   |   |   `-- raw
|   |   |-- docs
|   |   |   |-- commands.rst
|   |   |   |-- conf.py
|   |   |   |-- getting-started.rst
|   |   |   |-- index.rst
|   |   |   |-- make.bat
|   |   |   `-- Makefile
|   |   |-- LICENSE
|   |   |-- Makefile
|   |   |-- models
|   |   |-- notebooks
|   |   |-- README.md
|   |   |-- references
|   |   |-- reports
|   |   |   `-- figures
|   |   |-- requirements.txt
|   |   |-- src
|   |   |   |-- data
|   |   |   |   `-- make_dataset.py
|   |   |   |-- features
|   |   |   |   `-- build_features.py
|   |   |   |-- __init__.py
|   |   |   |-- models
|   |   |   |   |-- predict_model.py
|   |   |   |   `-- train_model.py
|   |   |   `-- visualization
|   |   |       `-- visualize.py
|   |   `-- tox.ini
|   `-- qml
|       |-- components
|       |   |-- BibleView.qml
|       |   |-- Placeholder.qml
|       |   `-- VerseDelegate.qml
|       |-- main.qml
|       |-- qml.qrc
|       `-- ui
|           |-- HomeTab.qml
|           `-- SettingsPage.qml
|-- tests
|   |-- CMakeLists.txt
|   |-- defines.h.cmake
|   `-- example_tests.cpp.example
|-- text.txt
|-- vendor
|   |-- CMakeLists.txt
|   `-- material
|       |-- CHANGELOG.md
|       |-- CONTRIBUTING.md
|       |-- demo
|       |   |-- BottomSheetDemo.qml
|       |   |-- ButtonDemo.qml
|       |   |-- CheckBoxDemo.qml
|       |   |-- ColorPaletteDemo.qml
|       |   |-- CustomIconsDemo.qml
|       |   |-- DatePickerDemo.qml
|       |   |-- demo.pro
|       |   |-- demo.qmlproject
|       |   |-- demo.qrc
|       |   |-- DialogDemo.qml
|       |   |-- FormsDemo.qml
|       |   |-- icons
|       |   |   |-- action_account_circle.svg
|       |   |   |-- action_autorenew.svg
|       |   |   |-- action_delete.svg
|       |   |   |-- action_language.svg
|       |   |   |-- action_settings.svg
|       |   |   |-- alert_warning.svg
|       |   |   |-- communication_email.svg
|       |   |   |-- content_add.svg
|       |   |   |-- content_create.svg
|       |   |   |-- content_forward.svg
|       |   |   |-- device_access_alarm.svg
|       |   |   |-- file_file_download.svg
|       |   |   |-- icons.qrc
|       |   |   |-- image_color_lens.svg
|       |   |   |-- image_edit.svg
|       |   |   |-- maps_place.svg
|       |   |   |-- navigation_arrow_drop_down.svg
|       |   |   `-- social_share.svg
|       |   |-- icons.yml
|       |   |-- images
|       |   |   |-- balloon.jpg
|       |   |   |-- go-last.color.svg
|       |   |   |-- list-add.color.svg
|       |   |   |-- weather-pouring.svg
|       |   |   `-- weather-sunset.svg
|       |   |-- ListItemsDemo.qml
|       |   |-- main.cpp
|       |   |-- main.qml
|       |   |-- PageStackDemo.qml
|       |   |-- ProgressBarDemo.qml
|       |   |-- RadioButtonDemo.qml
|       |   |-- SidebarPage.qml
|       |   |-- SliderDemo.qml
|       |   |-- SubPage.qml
|       |   |-- SwitchDemo.qml
|       |   |-- TextFieldDemo.qml
|       |   |-- TimePickerDemo.qml
|       |   `-- TypographyDemo.qml
|       |-- deploy_key.enc
|       |-- documentation
|       |   |-- images
|       |   |   `-- buttons.png
|       |   |-- material.qdoc
|       |   `-- material.qdocconf
|       |-- fonts
|       |   |-- fonts.qrc
|       |   |-- MaterialFontLoader.qml
|       |   |-- qmldir
|       |   `-- roboto
|       |       |-- Roboto-BlackItalic.ttf
|       |       |-- Roboto-Black.ttf
|       |       |-- Roboto-BoldItalic.ttf
|       |       |-- Roboto-Bold.ttf
|       |       |-- RobotoCondensed-BoldItalic.ttf
|       |       |-- RobotoCondensed-Bold.ttf
|       |       |-- RobotoCondensed-Italic.ttf
|       |       |-- RobotoCondensed-LightItalic.ttf
|       |       |-- RobotoCondensed-Light.ttf
|       |       |-- RobotoCondensed-Regular.ttf
|       |       |-- Roboto-Italic.ttf
|       |       |-- Roboto-LightItalic.ttf
|       |       |-- Roboto-Light.ttf
|       |       |-- Roboto-MediumItalic.ttf
|       |       |-- Roboto-Medium.ttf
|       |       |-- Roboto-Regular.ttf
|       |       |-- Roboto-ThinItalic.ttf
|       |       `-- Roboto-Thin.ttf
|       |-- icons
|       |   |-- core_icons.qrc
|       |   |-- navigation_arrow_back.svg
|       |   |-- navigation_chevron_left.svg
|       |   |-- navigation_chevron_right.svg
|       |   |-- navigation_close.svg
|       |   |-- navigation_menu.svg
|       |   `-- navigation_more_vert.svg
|       |-- icons.yml
|       |-- LICENSE
|       |-- LICENSE.CC-BY
|       |-- LICENSE.MPL
|       |-- material.pri
|       |-- qml-material.pro
|       |-- qpm.json
|       |-- README.md
|       |-- scripts
|       |   |-- build_docs.sh
|       |   |-- deploy.sh
|       |   |-- icons.py
|       |   |-- lint.sh
|       |   |-- make_awesome.py
|       |   |-- normalize_imports.sh
|       |   `-- qrc.py
|       |-- src
|       |   |-- components
|       |   |   |-- ActionButton.qml
|       |   |   |-- Card.qml
|       |   |   |-- components.qrc
|       |   |   |-- DatePicker.qml
|       |   |   |-- IconButton.qml
|       |   |   |-- OverlayLayer.qml
|       |   |   |-- OverlayView.qml
|       |   |   |-- ProgressCircle.qml
|       |   |   |-- Scrollbar.qml
|       |   |   |-- Snackbar.qml
|       |   |   |-- ThinDivider.qml
|       |   |   |-- TimePicker.qml
|       |   |   |-- Tooltip.qml
|       |   |   `-- Wave.qml
|       |   |-- controls
|       |   |   |-- Action.qml
|       |   |   |-- Button.qml
|       |   |   |-- CheckBox.qml
|       |   |   |-- controls.qrc
|       |   |   |-- Label.qml
|       |   |   |-- ProgressBar.qml
|       |   |   |-- RadioButton.qml
|       |   |   |-- Slider.qml
|       |   |   |-- Switch.qml
|       |   |   |-- Tab.qml
|       |   |   `-- TextField.qml
|       |   |-- core
|       |   |   |-- AwesomeIcon.qml
|       |   |   |-- awesome.js
|       |   |   |-- core.qrc
|       |   |   |-- device.cpp
|       |   |   |-- device.h
|       |   |   |-- FontAwesome.otf
|       |   |   |-- Icon.qml
|       |   |   |-- Ink.qml
|       |   |   |-- MaterialAnimation.qml
|       |   |   |-- Object.qml
|       |   |   |-- Palette.qml
|       |   |   |-- PlatformExtensions.qml
|       |   |   |-- ThemePalette.qml
|       |   |   |-- Theme.qml
|       |   |   |-- units.cpp
|       |   |   |-- units.h
|       |   |   |-- UnitsHelper.qml
|       |   |   |-- utils.js
|       |   |   `-- View.qml
|       |   |-- extras
|       |   |   |-- AutomaticGrid.qml
|       |   |   |-- CircleImage.qml
|       |   |   |-- CircleMask.qml
|       |   |   |-- ColumnFlow.qml
|       |   |   |-- extras.qrc
|       |   |   |-- Image.qml
|       |   |   `-- qmldir
|       |   |-- listitems
|       |   |   |-- BaseListItem.qml
|       |   |   |-- CMakeLists.txt
|       |   |   |-- Divider.qml
|       |   |   |-- listitems.qrc
|       |   |   |-- qmldir
|       |   |   |-- SectionHeader.qml
|       |   |   |-- SimpleMenu.qml
|       |   |   |-- Standard.qml
|       |   |   |-- Subheader.qml
|       |   |   `-- Subtitled.qml
|       |   |-- material.qrc
|       |   |-- plugin.cpp
|       |   |-- plugin.h
|       |   |-- popups
|       |   |   |-- BottomActionSheet.qml
|       |   |   |-- BottomSheet.qml
|       |   |   |-- Dialog.qml
|       |   |   |-- Dropdown.qml
|       |   |   |-- InputDialog.qml
|       |   |   |-- MenuField.qml
|       |   |   |-- Popover.qml
|       |   |   |-- PopupBase.qml
|       |   |   |-- popups.qrc
|       |   |   `-- TimePickerDialog.qml
|       |   |-- qmldir
|       |   |-- src.pro
|       |   |-- styles
|       |   |   |-- ApplicationWindowStyle.qml
|       |   |   |-- ButtonStyle.qml
|       |   |   |-- CheckBoxStyle.qml
|       |   |   |-- CMakeLists.txt
|       |   |   |-- ProgressBarStyle.qml
|       |   |   |-- qmldir
|       |   |   |-- RadioButtonStyle.qml
|       |   |   |-- SliderStyle.qml
|       |   |   |-- styles.qrc
|       |   |   |-- SwitchStyle.qml
|       |   |   |-- TextFieldStyle.qml
|       |   |   |-- ToolBarStyle.qml
|       |   |   `-- ToolButtonStyle.qml
|       |   `-- window
|       |       |-- ActionBar.qml
|       |       |-- ApplicationWindow.qml
|       |       |-- AppTheme.qml
|       |       |-- MainView.qml
|       |       |-- NavigationDrawerPage.qml
|       |       |-- NavigationDrawer.qml
|       |       |-- Page.qml
|       |       |-- PageSidebar.qml
|       |       |-- PageStack.qml
|       |       |-- Sidebar.qml
|       |       |-- TabBar.qml
|       |       |-- TabbedPage.qml
|       |       |-- Toolbar.qml
|       |       |-- Window.qml
|       |       `-- window.qrc
|       |-- styles_demo
|       |   |-- main.qml
|       |   `-- Makefile
|       |-- tests
|       |   |-- icons
|       |   |   |-- action_alarm.svg
|       |   |   |-- action_search.svg
|       |   |   |-- action_settings.svg
|       |   |   |-- content_add.svg
|       |   |   `-- icons.qrc
|       |   |-- icons.yml
|       |   |-- tests.cpp
|       |   |-- tests.pro
|       |   |-- tst_actionbar.qml
|       |   |-- tst_card.qml
|       |   `-- tst_pagestack.qml
|       `-- vendor.cmake
`-- win
|-- appicon.ico
|-- CMakeLists.txt
|-- installer.cmake.nsi
|-- installer.cmake.wxs
|-- qt.conf
`-- resources.rc

Как убрать эту ошибку из проекта?

0

Решение

Ты можешь использовать QDirIterator перепроверить, какие ресурсы содержит приложение. Например в main():

QDirIterator it(":/", QDirIterator::Subdirectories);
while (it.hasNext())
qDebug() << it.next();

Не зная, как обработка ресурсов Qt работает с CMake, я бы сказал, что следующие строки выглядят как преступник.

qt5_add_resources(RESOURCE_FILES ../resources/resources.qrc)

set(SOURCES
assets/assets.qrc
icons/icons.qrc
qml/qml.qrc)

Почему один .qrc добавлено с qt5_add_resources()тогда как остальные добавляются в SOURCES?

3

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]