Home>

I have an Item on top of the chapters. window. The task in it is to select the operating mode after which the window closes and displays the chapters. window. I haven't linked c++ classes yet so most of the similar questions didn't help. The error takes off: Unable to assign [undefined] to bool in the second case.

Case:

1-Creating two custom RadioButtons in the desired Item -> All OK;

2-Calling two custom RadioButtons in the desired Item from a separate file -> ERROR on 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 //!!!!!!!!!! error !!!!!!!!!!!!
        }
    }
    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
    }
}

Place of call: conditionally 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
                        }

Closing the Item works, but I was planning to continue using this template. I don't know if this error will hurt so I decided to ask for help.

Try removing parent and leaving only checked

Alexander Chernin2021-10-13 10:38:05

@AlexanderChernin, helped thanks. no mistakes.

Anton-Vas2021-10-13 11:05:17