This is my first time asking a question, so please be chill if I do something wrong.
Hello,
- My Visual Studio solution is generated by CMake.
- Code is in C++ (and QML).
- I'm creating a QtQuick window which uses .qml files to generate its content.
When I run the built application from Visual Studio (2017 RC) the app gives a common
"Component not ready" error message.
But if I run the same .exe file manually, everything is working perfectly.
I suspect it must be some kind of a mistake in my CMakeLists causing Visual Studio searching for files in the wrong place but I have no idea what that mistake could be.
C++ code fail part:
...
QQmlComponent guiComponent(qmlEngine,
QUrl::fromLocalFile(APP_RESOURCES"/qml/GUI.qml"));
guiRoot = qobject_cast<QQuickItem *>(guiComponent.create());
guiRoot->setParentItem(mainWindow->contentItem());
qDebug() << guiComponent.errors();
...
My CMakeLists:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "[MyProjectName]")
set(APP_NAME "[MyProjectName]")
project(${PROJECT_NAME})
set(CMAKE_AUTORCC ON )
set(CMAKE_AUTOUIC ON )
set(CMAKE_AUTOMOC ON )
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules;${CMAKE_MODULE_PATH}")
find_package(Qt5 REQUIRED Quick QuickWidgets)
find_package(QtImageLoader REQUIRED HINTS ${CMAKE_SOURCE_DIR}/addons/QtImageLoader/cmake)
find_package(AssimpModelLoader REQUIRED HINTS ${CMAKE_SOURCE_DIR}/addons/AssimpModelLoader/cmake)
find_package(GPUEngine REQUIRED geGL geSG)
set(SRC_ROOT "${CMAKE_SOURCE_DIR}/src")
set(SRC_FILES "")
set(INCLUDE_DIRS "")
add_subdirectory(src)
list(APPEND SRC_FILES ${src_SRC_FILES})
list(APPEND INCLUDE_DIRS ${src_INCLUDE_DIRS})
message("Located source files:")
FOREACH(_FILE ${SRC_FILES})
message("- ${_FILE}")
ENDFOREACH()
message("Located include directories:")
FOREACH(_DIRE ${INCLUDE_DIRS})
message("- ${_DIRE}")
ENDFOREACH()
source_group(TREE ${SRC_ROOT} PREFIX "src" FILES ${SRC_FILES})
add_executable(${APP_NAME} ${SRC_FILES})
target_include_directories(${APP_NAME} PUBLIC ${INCLUDE_DIRS})
target_link_libraries(${APP_NAME} Qt5::Quick Qt5::QuickWidgets geGL geSG AssimpModelLoader QtImageLoader)
set_target_properties(${APP_NAME} PROPERTIES COMPILE_DEFINITIONS "APP_RESOURCES=\"Data\"")
set_property(TARGET ${APP_NAME} PROPERTY FOLDER "${APP_NAME}")
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/libs/$<CONFIG>"
"$<TARGET_FILE_DIR:[MyProjectName]>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/resources"
"$<TARGET_FILE_DIR:[MyProjectName]>/Data"
)
Edit: I had this problem for a long time now (months) and didn't bother to fix it because running the application manually was sufficient. But now I want to use Visual Studio's debugging tools and I can't.