Qt6 running an example from the documentation
-
Hello, I am trying to run an example from the documentation
Unfortunately it doesn't come up with any instructions on how to run it with CMake.
I see that there is a CMakeLists.txt file and the only thing I have added is a line, so I can point to where my Qt6 installation is.
That's the changed CMakeLists.txt file:
cmake_minimum_required(VERSION 3.16) project(androidnotifier LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(CMAKE_PREFIX_PATH "/home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake") # THAT'S WHAT I HAVE ADDED find_package(Qt6 COMPONENTS Widgets REQUIRED) set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/corelib/platform/androidnotifier") set(PROJECT_SOURCES main.cpp notificationclient.cpp notificationclient.h ) if(ANDROID) qt_add_executable(androidnotifier MANUAL_FINALIZATION ${PROJECT_SOURCES}) target_link_libraries(androidnotifier PRIVATE Qt6::Widgets) set_property(TARGET androidnotifier APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android) qt_finalize_executable(androidnotifier) set(qml_resource_files "images/happy.png" "images/sad.png" ) qt6_add_resources(androidnotifier "main" PREFIX "/" FILES ${qml_resource_files} ) install(TARGETS androidnotifier RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) endif()
However, after running
cmake .
I get
-- Could NOT find Qt6WidgetsTools (missing: Qt6WidgetsTools_DIR) CMake Warning at /home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6/Qt6Config.cmake:209 (find_package): Found package configuration file: /home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake but it set Qt6Widgets_FOUND to FALSE so package "Qt6Widgets" is considered to be NOT FOUND. Reason given by package: Target "Qt6::Widgets" was not found. Call Stack (most recent call first): CMakeLists.txt:15 (find_package) CMake Error at CMakeLists.txt:15 (find_package): Found package configuration file: /home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find Qt component "Widgets". Expected Config file at "/home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake" exists
I'd basically would want to build the example and run it on my mobile phone.
I have been running through forums, including this one, but I haven't found anything to help me out.
Could someone explain me what's wrong and try to guide me through how to fix it please ?
-
@Ivelin Qt 6.2.4 is kind of old. Try to install Qt6.6.1. I tested your Android example with Qt 6.6.1 and got errors. Will check it out later.
Run the example in Qt Creator like
qtcreator(comes with 6.6.1) CMakeLists.extcmake alone will not work because NDK, SDK and JDK paths are not set.
-
@JoeCFD, I think I found a way to make that work
I have changed 2 lines in Qt6Config.cmake from
set(Qt6_FOUND FALSE)
to
set(Qt6_FOUND TRUE)
I ran
cmake .
and I got CMakeFiles forder with a notificaitonclient.cpp, CMakeCache.txt and cmake_install.cmake
but now what ? Even though the command output is
-- Configuring done -- Generating done -- Build files have been written to: /home/ivelin/Qt/Examples/Qt-6.2.4/corelib/platform/androidnotifier
I find no executable apk file ? Why is that?
What else do I have to do ?
-
-
@JoeCFD, thank you for providing this information. I have clearer picture right now, but I got another problem
At the moment after I do
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=26 .
I get
-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Error at CMakeLists.txt:16 (find_package): By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6", but CMake did not find one. Could not find a package configuration file provided by "Qt6" with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred! See also "/home/ivelin/Qt/Examples/Qt-6.2.4/corelib/platform/androidnotifier/CMakeFiles/CMakeOutput.log".
which is weird because when I do
cmake .
only
I get
-- The CXX compiler identification is GNU 9.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for C++ include pthread.h -- Looking for C++ include pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - yes -- Found Threads: TRUE -- Could NOT find Qt6WidgetsTools (missing: Qt6WidgetsTools_DIR) CMake Warning at /home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6/Qt6Config.cmake:209 (find_package): Found package configuration file: /home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake but it set Qt6Widgets_FOUND to FALSE so package "Qt6Widgets" is considered to be NOT FOUND. Reason given by package: Target "Qt6::Widgets" was not found. Call Stack (most recent call first): CMakeLists.txt:16 (find_package) -- Configuring done -- Generating done -- Build files have been written to: /home/ivelin/Qt/Examples/Qt-6.2.4/corelib/platform/androidnotifier
Why is that ? Could you help me out ?
-
@JoeCFD said in Qt6 running an example from the documentation:
/home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6"
I have set it in the CMakeLists.txt file as
set(CMAKE_PREFIX_PATH "/home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6")
Now I get
-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning at CMakeLists.txt:15 (find_package): By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6", but CMake did not find one. Could not find a package configuration file provided by "Qt6" with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:26 (qt_add_executable): Unknown CMake command "qt_add_executable". -- Configuring incomplete, errors occurred! See also "/home/ivelin/Qt/Examples/Qt-6.2.4/corelib/platform/androidnotifier/CMakeFiles/CMakeOutput.log".
-
@JoeCFD, I have made some progress.
As I said I have downloaded Qt6 from the Qt Maintenance. I looked in the Qt/6.2.4 folder and saw there there is a qt.toolchain.cmake file in Qt/6.2.4/android_x86_64/lib/cmake/Qt6/qt.toolchain.cmake, so I used that one.
It gave me an error that it is searching for /opt/android/android-ndk-r22b, but I hadn't had /opt/android, so I created a folder and downloaded the anroid-ndk-r22b file from the official android ndk downloads. It was also searching for an sdk, but I already had one ( Don't remember where I got it from )
After that I ran this command:
cmake -DCMAKE_TOOLCHAIN_FILE=/home/ivelin/Qt/6.2.4/android_x86_64/lib/cmake/Qt6/qt.toolchain.cmake .
I got
-- The CXX compiler identification is Clang 11.0.5 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/android/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for C++ include pthread.h -- Looking for C++ include pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - yes -- Found Threads: TRUE -- Performing Test HAVE_STDATOMIC -- Performing Test HAVE_STDATOMIC - Success -- Found WrapAtomic: TRUE -- Performing Test HAVE_EGL -- Performing Test HAVE_EGL - Success -- Found EGL: /opt/android/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include (found version "1.5") -- Performing Test HAVE_GLESv2 -- Performing Test HAVE_GLESv2 - Success -- Found GLESv2: /opt/android/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -- Found WrapVulkanHeaders: /opt/android/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -- Found android platform plugin at: /home/ivelin/Qt/6.2.4/android_x86_64/./plugins/platforms/libplugins_platforms_qtforandroid_x86_64.so -- Configuring done -- Generating done -- Build files have been written to: /home/ivelin/Qt/Examples/Qt-6.2.4/corelib/platform/androidnotifier
which seems like a successful build. Then I ran make and got
Why is that ? Any ideas on how to fix it ?
-
@JoeCFD, sorry that was a stupid mistake from mine.
I have installed the corresponding SDK from Android Studio and moved the file from where the Android Studio was configured to download it to where qt6 cmake is searching for it - /opt/android and now it is working.
Thank you for your patience and support. I wouldn't make it without your patience and guidance.
Cheers.
-