我有PyQt5
属性notify
- 函数:
class FriendsWidgetBackend(QObject):
messageCompanionChanged = pyqtSignal()
def __init__(self, parent=None):
QObject.__init__(self, parent)
self._current_message_companion = None
@pyqtProperty('QVariant', notify=messageCompanionChanged)
def message_companion(self):
return QVariant(self._current_message_companion)
@message_companion.setter
def message_companion(self, message_companion):
self._current_message_companion = message_companion
self.messageCompanionChanged.emit()
一切正常,直到我分配给这个变量undefined
- 它在发出messageCompanionChanged
信号后拒绝更新qml中的变量。我甚至试图设置一个断点 - 它从应用程序开始更新到undefined
赋值:
Item {
id: rootItem
property QtObject friendsWidgetBackend
onVisibleChanged: {
if (!visible) {
friendsWidgetBackend.message_companion = undefined
}
}
}
我会说C#
经历了QML
之后Column {
visible: friendsWidgetBackend.message_companion ? true : false
}
断开绑定后的约束。我该如何避免这种行为?
P.S。我的绑定示例:
messageCompanionChanged
P.P.S。即使没有绑定它也不起作用 - 只是尝试从QML连接到undefined
信号 - 它在发射后不会更新值。
P.P.P.S。如果我将{}
更改为空{s}对象,例如({})
或{{1}}绑定将起作用,但这不是我需要的。