Unable to assign [undefined] to bool для RadioButton
У меня есть некий Item поверх глав. окна. Задача в нем выбрать режим работы после чего окно закрывается и отображает глав. окно. Я еще не привязывал классы С++ так что большинство похожих вопросов не помогли. Вылетает ошибка: Unable to assign [undefined] to bool во втором случае.
Случай:
1- Создание двух кастомных RadioButton в нужном Item -> Все ОК;
2- Вызов двух кастомных RadioButton в нужном Item из отдельного файла -> ОШИБКА на visible: parent.checked.
DarkRadioButton.qml
import QtQuick 2.14
import QtQuick.Controls 2.14
RadioButton {
checked: false
indicator: Rectangle {
implicitWidth: 20
implicitHeight: 20
x: payloadRole.horizontalPadding
y: payloadRole.height / 2 - height / 2
radius: 0
border.color: Qt.rgba( 255/255., 0/255., 0/255., 1)
color: Qt.rgba( 32/255., 32/255., 32/255., 1)
Rectangle {
id: radioButtonBox
width: 16
height: 16
x: 2
y: 2
Image {
anchors.fill: radioButtonBox
source: "qrc:/res/resources/DarkRadioButtonBox.png"
fillMode: Image.PreserveAspectCrop
sourceSize.width: 200
sourceSize.height: 200
}
visible: parent.checked //!!!!!!!!!! ошибка !!!!!!!!!!!!
}
}
contentItem: Text {
text: parent.text
font: parent.font
color: Qt.rgba( 255/255., 255/255., 255/255., 1)
verticalAlignment: Text.AlignVCenter
leftPadding: parent.indicator.width + parent.spacing
}
onCheckedChanged: {
//some extern value function (not here yet)
optionsWindow.visible = false
}
}
Место вызова: условно main.qml
//---
Item {
//---
ColumnLayout{
width: dialog.width
height: dialog.height
DarkRadioButton {
id: optionA
text: qsTr("Option 1")
Layout.alignment: Qt.AlignCenter
}
DarkRadioButton {
id: optionB
text: qsTr("Option 2")
Layout.alignment: Qt.AlignCenter
}
Закрытие Item-а срабатывает, но я планировал и дальше использовать данный шаблон. Не знаю помешает ли эта ошибка так что решил попросить помощи.
Ответы (1 шт):
У вас в качестве родительского объекта выступает Rectangle, у которого нет свойства checked.
Исправленный вариант
import QtQuick 2.14
import QtQuick.Controls 2.14
RadioButton {
id: radioButtonRoot_
checked: false
indicator: Rectangle {
implicitWidth: 20
implicitHeight: 20
x: payloadRole.horizontalPadding
y: payloadRole.height / 2 - height / 2
radius: 0
border.color: Qt.rgba( 255/255., 0/255., 0/255., 1)
color: Qt.rgba( 32/255., 32/255., 32/255., 1)
Rectangle {
id: radioButtonBox
width: 16
height: 16
x: 2
y: 2
Image {
anchors.fill: radioButtonBox
source: "qrc:/res/resources/DarkRadioButtonBox.png"
fillMode: Image.PreserveAspectCrop
sourceSize.width: 200
sourceSize.height: 200
}
visible: radioButtonRoot_.checked
}
}
contentItem: Text {
text: parent.text
font: parent.font
color: Qt.rgba( 255/255., 255/255., 255/255., 1)
verticalAlignment: Text.AlignVCenter
leftPadding: parent.indicator.width + parent.spacing
}
onCheckedChanged: {
//some extern value function (not here yet)
optionsWindow.visible = false
}
}