I'm constructing an application via Python as backend and QT QML as frontend.
I use Win10, PyCharm 2022.3.1 (Community Edition), Pyside6 and QT Design Studio (not QT Creator). All libraries installed by pip using terminal or through PyCharm library manager.
Everything was fine exactly until I tried to import a separate Python file with code designed to send messages to the CAN bus using a third-party python library canlib by Kvaser. Other imported libraries such as Pandas or ElementTree work fine.
The issue is that the QQmlApplicationEngine failed to load component when I'm trying to import this file.
The error from terminal sounds like: (venv) PS C:\Users\Alexa\PycharmProjects\LEET\venv> python LEET.py QQmlApplicationEngine failed to load component file:///D:/LEET/QtDesignProjects/LEET/LEET.qml:1:1: Cannot load library C:\Users\Alexa\PycharmProjects\LEET\venv\lib\site-p ackages\PySide6\qml\QtQuick\qtquick2plugin.dll
My main file (LEET.py):
import sys
from PySide6.QtGui import QGuiApplication, QIcon
from PySide6.QtQml import QQmlApplicationEngine, QmlElement, qmlRegisterType
from Broadcast import BroadcastRequest # here I try to import file with this external library
qmlRegisterType(BroadcastRequest, 'sendSingle', 1, 0, 'BroadcastRequest')
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
app.setWindowIcon(QIcon("D:\\Midjourney_logos\\LEET_icon_small.png"))
\#Get Context
broadcastSingleMessage = BroadcastRequest()
engine.rootContext().setContextProperty('manualSendConnection', broadcastSingleMessage)
engine.load('D:\\LEET\\QtDesignProjects\\LEET\\LEET.qml')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
My Broadcast.py starts like this:
from canlib import canlib # this is a root cause. If I comment out this canlib import, problem disappears
My QML file starts like this:
import QtQuick 2.0 # engine stops here, but I'm not sure that this is a reason
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.0
import QtQuick.Window 2.3
I discovered that if I try to import canlib from canlib, engine fails. If I erase this import, no error appears. Maybe there's any incompatibility between QML and canlib? On kvaser (lib manufacturer) site it's mentioned that module canlib.canlib located in canlib32.dll. 32bits is a reason? Update: I've found in driver installation that it selects 32/64 automatically depends of Win version so it's 64bits dll obviously. PyCharm shows no error also, all works great, just QML engine has this issue.