Qt 5.15.2 Raspberry Pi 4 cross-compile with CMake. 'module "QtQuick.Window" is not installed'
-
How can I tell my Qt application where the modules are when it runs?
I followed some tutorials online on how to cross-compile Qt 5.15.2 for the Raspberry Pi, including (but not limited to) this one: https://mechatronicsblog.com/cross-compile-and-deploy-qt-5-12-for-raspberry-pi/
I was able to get the code compiled and moved over to the Pi. My Qt project builds and deploys fine (and runs locally), but will not run on the Pi due to the missing QtQuick module.
However, I do have QtQuick on my Pi at/usr/local/qt5.15/qml/QtQuick
. These are the individual modules in the folder:Controls Extras Particles.2 Scene3D Timeline XmlListModel Controls.2 Layouts PrivateWidgets Shapes VirtualKeyboard Dialogs LocalStorage Scene2D Templates.2 Window.2
My main.qml is simple:
import QtQuick 2.15 import QtQuick.Window 2.15 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") }
I have a CMake toolchain file that looks like this:
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_INSTALL_PREFIX /home/pi/install) set(CMAKE_PREFIX_PATH /usr/local/qt5.15) set(PI_ROOT /home/fahad/pi) set(CMAKE_SYSROOT ${PI_ROOT}/sysroot) set(CROSS_COMPILER ${PI_ROOT}/tools) set(CMAKE_C_COMPILER ${CROSS_COMPILER}/arm-linux-gnueabihf-gcc) set(CMAKE_CXX_COMPILER ${CROSS_COMPILER}/arm-linux-gnueabihf-g++) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
I thought the
set(CMAKE_PREFIX_PATH /usr/local/qt5.15
line would tell the Qt application where the modules are when it runs. -
On the Raspberry Pi, in the terminal before running my application, I had to run
export QML2_IMPORT_PATH=/usr/local/qt5.15/qml
and that fixed it.I put that line in my ~/.profile and it seems to have fixed it permanently. I no longer have to run the export command manually.