Create a Standalone exe Qt6
-
I'm just starting with Qt6 having used Qt4 and 5 some time ago. I have a simple QML with a C++ class. For testing purposes the QML simply uses some data from the C++ class, and calls a simple function. In the past I've use QMake but am now using CMAKE since I need to make the transiition. I'm on Windows 10 pro. Qt community is installed.
The project can be built and runs successfully - from QT Creator 8. I want to deploy it to a Release directory with all the needed dlls, etc. From the research I've been doing you can use the winqtdeploy tool but documents from Qt and others indicate I can do that in my CMAKELists.txt file. From what I understand of qt_generate_deploy_qml_app_script it is supposed to deploy all the needed dlls and other items when the application is deployed (I've used Build -> Deploy to deploy it until I can figure out how to set the project up to do it. I've told install Targets to put the RUNTIME DESTINATION as .. (one up from the build directory). but nothing is done other than create the exe in the build directory which obviously doesn't run standalone.
I've gone through many, many references but can't get the project to deploy the exe with needed files in the correct directory. I'm attaching the CMakeLists.txt for reference and any help on A) how to get this to build a standalone and B) set the project up to deploy it automatically would be appreciated.
Thank you.
This is the file created by Qt when I created the new project with the additions I've noted.
cmake_minimum_required(VERSION 3.16) project(FlightLog VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Added set set(appName "FlightLogbook") find_package(Qt6 COMPONENTS Quick REQUIRED) #Added these to finds hoping it would help. # Core is probably redundant due to Quick find find_package(Qt6 COMPONENTS Core REQUIRED) find_package(Qt6 COMPONENTS Qml REQUIRED) qt_add_executable(FlightLogbook main.cpp ) # Added Sources to this qt_add_qml_module(FlightLogbook URI FlightLog VERSION 1.0 QML_FILES main.qml SOURCES import/import.h import/import.cpp ) set_target_properties(FlightLogbook PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) # Added Core, Qml as private libraries target_link_libraries(FlightLogbook PRIVATE Qt6::Core PRIVATE Qt6::Quick PRIVATE Qt6::Qml) # Attempting to get a build that runs stanalone qt_generate_deploy_qml_app_script( TARGET FlightLogbook FILENAME_VARIABLE deploy_script DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM NO_UNSUPPORTED_PLATFORM_ERROR ) # Attempting to put the runtime result in the directory above the build install(TARGETS FlightLogbook BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION .. ) # This is supposed to run the deploy script to create a standalone in the directory given above. install(SCRIPT ${deploy_script}) -
Which Qt version are you testing this with?
-
Do I need to use the winqt deployment tool to get the needed libraries, dlls, etc. into my project? I had thought that the qt_generate_deploy_qml_app_script would take care of that for me but maybe not??
For future reference here is what I did to work around.
First, based on the documentation I thought qt_generate_deploy_qml_script was supposed to do what winqtdeploy did which is scan the exe and dependencies such as Qtcore.dll, etc. Evidently that is not true - at least based on my experience but if I'm wrong I would appreciate knowing how to use it so it does this. So I really don't know what qt_generate_deploy_qml_script does or it's purpose.
I fell back to winqtdeploy and ran it in the directory the exe was in. This worked as it generated the folders and files so I could run my exe as a standalone.
At some point I plan to try adding winqtdeply as a command to the CMakeLists.txt to pick up any changes needed.