QML_IMPORT_NAME = "io.qt.textproperties"
QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
class Backend(QObject):
updated=Signal(str)
def init(self):
super().init()
self.updated.emit("IM")
if name == "main":
CURRENT_DIRECTORY = Path(file).resolve().parent
app = QGuiApplication(sys.argv)
format = QSurfaceFormat()
format.setSamples(4)
QSurfaceFormat.setDefaultFormat(format)
engine = QQmlApplicationEngine()
engine.addImportPath(f"{os.path.dirname(file)}")
QQuickStyle.setStyle("CStyles")
engine.setOfflineStoragePath(os.fspath(CURRENT_DIRECTORY))
backend = Backend()
engine.load(os.fspath(CURRENT_DIRECTORY / "main.qml"))
engine.rootObjects()[0].setProperty('sender', backend)
engine.quit.connect(app.quit)
def handle_status_changed(status):
if status == QQuickView.Error:
QtCore.QCoreApplication.exit(-1)
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
import QtQuick.LocalStorage
Window {
id: wcs
width: 1024
height: 600
visible: true
visibility: Window.AutomaticVisibility
modality: Qt.ApplicationModal
flags: Qt.Window
property QtObject sender
.
.
.
Connections {
target: sender
function onUpdated(msg) {
console.log("Hello");
}
}
Backend{
id: bridge
}
M.A Mousavipragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
import QtQuick.LocalStorage
Window {
id: wcs
width: 1024
height: 600
visible: true
visibility: Window.AutomaticVisi
and this one is my qml code. the problem is that i was able to send signals from python to qml and log it on console 3 days ago. and now its not working.
It seems that i need to ask if it is possible that a python class be used as @QmlElement for bridge inside qml and also emits signals to qml file and run a python qthread and communicate with signal and slot or not?
Because it might be a bug. I need to be more percise explaining this. I'm having a python main.py which is loading a qml main.qml file. It consists of a class. Inside class,s initiator i start a qthread the class is defined with @QmlElement and is being used as a bridge inside qml. There are @QtCore.slot(str) s which are connected to qml elements such as buttons. After clicking on button the slot will run correctly and pass a signal to qthread. The qthread has a signal inside, that is connected to main.py and returning results of theead to main.py there is a def inside main.py that is connected to qthread signal. From inside this def i emit result of qthread to qml connections{}
The problem is that when i simply emit some string from qthread to main.py and emit that to qml it will be successful. But when i use a simple if clause inside qthreads def run(self): it emits the signal to main.py and i can print it there but then i cannot emit what i received to qml.
Apologize about being some how long and complicated
Replymessage unavailable
That is a known transition to new enums. See https://doc.qt.io/qtforpython-6/considerations.html#doing-a-smooth-transition-from-the-old-enums
As for the rest, that's the downside of PySide6 currently. I do hope they fix the issues in 6.6.1.
Markus BauerHey
I am calling a model from 2 different positions in my QML app. Can I somehow get the parent in a way I can distinguish between the two places?
I have to give back the "rowCount" different, one filtered, the other one unfiltered
Ссылка
click to show
click to show
Not sure I fully understand, but if you're filtering - wouldn't a QSortFilterProxyModel for one of them be what you're looking for?
There is a QML module that exposes QSortFilterProxyModel to QML that would help with that:
https://github.com/oKcerG/SortFilterProxyModel
However it has C++ backing to it. You could port it to PySide6 though.
ThomasQSortFilterProxyModel is the answer, though. It confuses me that it is not available to QML contexts.
See my link above ^^
This provides it to QML.