QML Import Path issue
-
wrote on 2 Apr 2024, 08:02 last edited by
Hey
I Have several Singleton classes and exported them with:QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1
This actually never changed and the path itself was generated from Qt Creator.
In QML I import them like:
import io.qt.textproperties 1.0
At some point everything was running and I wanted to rename a Python class before I commit.
Well... after renaming the Python class and renaming also the qml files nothing works.QQmlApplicationEngine failed to load component file:///Users/.../view/main.qml:5:1: module "io.qt.textproperties" is not installed
I deleted the folder 'io' and hoped to get it recreated by Qt Creator. I also deleted pycache folder even restarted my machine ... but nothing works.
I also asked copilot to analyze my error but he also says everything is fine.I have now commited to this repository although application is not running: link
I appreciate every hints :-)
-
@LS-KS
I created a new project as minimal example.
This should work right?# This Python file uses the following encoding: utf-8 import sys from pathlib import Path from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() qml_file = Path(__file__).resolve().parent / "main.qml" engine.load(qml_file) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())
# This Python file uses the following encoding: utf-8 from PySide6 import QtCore from PySide6.QtQml import QmlElement, QmlSingleton QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1 @QmlElement @QmlSingleton class Controller(QtCore.QObject): addedOne = QtCore.Signal(int) def __init__(self, parent = None): super().__init__(parent) @QtCore.Slot(int) def addOne(self, value: int): self.addedOne.emit(value + 1)
main.qml
import QtQuick import QtQuick.Window import QtQuick.Layouts import io.qt.textproperties 1.0 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Column{ TextField{ id: input text: 0 Connections{ target: Controller function onAddedOne(result){ text = result } } } Button{ text: "add one" onClicked: Controller.addOne(input.text) } } }
Output:
QQmlApplicationEngine failed to load component file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.
wrote on 2 Apr 2024, 09:25 last edited by@LS-KS
stupid me:Since main.py doesn't refer to anything from controller.py it was labelled as unused import.
I didn't think when I hit the shortcut to optimize imports. -
Hey
I Have several Singleton classes and exported them with:QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1
This actually never changed and the path itself was generated from Qt Creator.
In QML I import them like:
import io.qt.textproperties 1.0
At some point everything was running and I wanted to rename a Python class before I commit.
Well... after renaming the Python class and renaming also the qml files nothing works.QQmlApplicationEngine failed to load component file:///Users/.../view/main.qml:5:1: module "io.qt.textproperties" is not installed
I deleted the folder 'io' and hoped to get it recreated by Qt Creator. I also deleted pycache folder even restarted my machine ... but nothing works.
I also asked copilot to analyze my error but he also says everything is fine.I have now commited to this repository although application is not running: link
I appreciate every hints :-)
wrote on 2 Apr 2024, 09:12 last edited by@LS-KS
I created a new project as minimal example.
This should work right?# This Python file uses the following encoding: utf-8 import sys from pathlib import Path from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() qml_file = Path(__file__).resolve().parent / "main.qml" engine.load(qml_file) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())
# This Python file uses the following encoding: utf-8 from PySide6 import QtCore from PySide6.QtQml import QmlElement, QmlSingleton QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1 @QmlElement @QmlSingleton class Controller(QtCore.QObject): addedOne = QtCore.Signal(int) def __init__(self, parent = None): super().__init__(parent) @QtCore.Slot(int) def addOne(self, value: int): self.addedOne.emit(value + 1)
main.qml
import QtQuick import QtQuick.Window import QtQuick.Layouts import io.qt.textproperties 1.0 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Column{ TextField{ id: input text: 0 Connections{ target: Controller function onAddedOne(result){ text = result } } } Button{ text: "add one" onClicked: Controller.addOne(input.text) } } }
Output:
QQmlApplicationEngine failed to load component file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.
-
@LS-KS
I created a new project as minimal example.
This should work right?# This Python file uses the following encoding: utf-8 import sys from pathlib import Path from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() qml_file = Path(__file__).resolve().parent / "main.qml" engine.load(qml_file) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())
# This Python file uses the following encoding: utf-8 from PySide6 import QtCore from PySide6.QtQml import QmlElement, QmlSingleton QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1 @QmlElement @QmlSingleton class Controller(QtCore.QObject): addedOne = QtCore.Signal(int) def __init__(self, parent = None): super().__init__(parent) @QtCore.Slot(int) def addOne(self, value: int): self.addedOne.emit(value + 1)
main.qml
import QtQuick import QtQuick.Window import QtQuick.Layouts import io.qt.textproperties 1.0 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Column{ TextField{ id: input text: 0 Connections{ target: Controller function onAddedOne(result){ text = result } } } Button{ text: "add one" onClicked: Controller.addOne(input.text) } } }
Output:
QQmlApplicationEngine failed to load component file:///Users/.../qmlelementtest/main.qml:5:1: module "io.qt.textproperties" is not installed
the folder io.qt.textproperties is only created when I use QtCreators build functionality. With PyCharm / VsCode there will be no directory created which contains qmldir.
wrote on 2 Apr 2024, 09:25 last edited by@LS-KS
stupid me:Since main.py doesn't refer to anything from controller.py it was labelled as unused import.
I didn't think when I hit the shortcut to optimize imports. -
1/3