How to install QT libraries correctly in 2024? QT Creator

92 Views Asked by At

I'm a beginner and thought that writing apps in QT Creator will be as easy as working with vanilla Python in VSCode & installing packages to venv with pip. Sadly that's not in case.

I want to create a desktop app in Qt Quick with charts, plots and animations. I downloaded the QT online installer and chose the following installation template: enter image description here

Then, in the QT Maintenance application, I ticked the 'QTCharts' box under QT/6.6.2/Additional Libraries and installed it.

enter image description here

enter image description here

I created a new Project in QT Creator with an empty QT Quick window. Launched it, it worked (why wouldn't it?). I then added the import statement for QTCharts in the main.qml file:

import QtQuick
import QtQuick.Window
import QtCharts

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

but when I ran it via the QT Creator UI, it simply logged: '\venv\Scripts\python.exe exited with code -1'. Surprised by the lack of details, I ran the app via cmd which outputted more information:

"main.qml:3:1: module "QtCharts" is not installed".
Quick google led me to adding the following:

engine.addImportPath("C:\Qt\\6.6.2\mingw_64\qml")

to the main.py file. This resulted in yet another error:

main.qml:3:1: Cannot load library C:\Qt\6.6.2\mingw_64\qml\QtCharts\qtchartsqml2plugin.dll: The specified module could not be found.

but the file does indeed exist:
enter image description here

so this made me stop. I'm not doing it right, there should be an easier way. I've got many libraries to install, some external ones too, so I need to know a straightforward way of adding them to my project. Please, could anyone explain what I'm doing wrong?

Windows 10, Python 3.11

1

There are 1 best solutions below

0
mugiseyebrows On

You cannot use c++ binary in python unless it's binary compatible with python. c++ library is binary compatible with python if its build with same compiler that python was build. As far as I know Qt does not ship python and "Qt for python" uses whatever python that is found on user machine, so there's no way to ship binaries compatible with this python using maintenance tool. It's easy and natural to use python tooling to ship this binaries, which they do.

When you create new "Qt for python" project in creator, it runs python.exe -m pip install PySide6 in virtual environment. PySide6 depends on PySide6-Addons and PySide6-Essentials, so command installs all binaries, bindings and plugins, including QtCharts qml plugin <venv-root>\Lib\site-packages\PySide6\qml\QtCharts\qtchartsqml2plugin.dll. You can see log of this command in General Messages tab in qtcreator.

General Messages tab

PySide6 is self-contained within this venv and does not depend on anything outside.

To configure python associated with Qt go to Edit -> Preferences -> Python in qtcreator.

To verify that qml charts actually work you can run polarchart pyside qml example, which you can clone from pyside repository git clone --depth 1 git://code.qt.io/pyside/pyside-setup.git (pyside-setup\examples\charts\qmlpolarchart)