Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Slider is not a type



  • I just updated Qt creator to 4.11.1 and installed QtQuick 5.14.1. It was probably a year out of date before that (not sure which version exactly) but I was using QtQuick 5.12. I use the Slider QML type quite a bit in my project and since updating, I get the error at runtime "Slider is not a type" when I try to load any page that uses it. This code worked fine just before the update.

    Below is an example of one instance where I'm using it along with my import statements. Any ideas on what happened?

    import QtQuick 2.12
    import QtQuick.Dialogs 1.2
    import QtQuick.Controls 2.14
    
    Slider {
        id: compositeIntervalSet
        height: parent.height
        width: parent.width
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
        from: 
        to: 255
        stepSize: 1
        snapMode: Slider.SnapOnRelease
        Component.onCompleted: {
            compositeIntervalSet.value = myClass.composite.timeLimit
            myClass.composite.timeLimit = Qt.binding(function() { return compositeIntervalSet.value })
        }
        handle: Rectangle {
            x: parent.leftPadding + parent.visualPosition * (parent.availableWidth - width)
            y: parent.topPadding + parent.availableHeight / 2 - height / 2
            implicitWidth: parent.height*.8
            implicitHeight: parent.height*.8
            radius: parent.height*.4
            color: parent.pressed ? "#480090" : "#000000"
            border.color: "#ffffff"
            border.width: 4
            Image {
                anchors.fill: parent
                anchors.margins: 0.15*parent.width
                source: "SpeedIcon.png"
                sourceSize.height: 128
                sourceSize.width: 128
            }
        }
    }
    

  • Moderators

    The snippet misses a setting for from, but I don't think that is causing the problem since it would give a different error message then. It works fine for me locally, so it might be something that Slider depends on that is missing somehow. Can you provide the full error you get as there is sometimes some more lines in the run up indicating why Slider could not be found.



  • Here is a larger snip including the Item to which the Slider is a member.

    The full error is qrc:/home.qml:778:9: Slider is not a type. Line 778 is the first line that declares the Slider object.

    Item {
        id: compositeInterval
        height: begin.portrait ? .06*begin.height : .10*begin.height
        width: begin.portrait ? .91 * begin.width - 0.16*begin.height : (myClass.targetDevice.quickSwitches ? .80 * begin.width - 0.32*begin.height : .91 * begin.width - 0.32*begin.height)
        anchors.verticalCenter: compositeStart.verticalCenter
        anchors.left: compositeSave.right
        anchors.leftMargin: begin.portrait ? .02*begin.width : .01*begin.width
        visible: myClass.composite.length > 0
        Text {
            id: compositeIntervalTime
            font.pixelSize: 0.2 * compositeInterval.height
            text: myClass.composite.timeLimitString
            font.family: "Helvetica"
            anchors.top: parent.top
            anchors.left: parent.left
            color: "#FFFFFF"
        }
        Text {
            id: compositeIntervalLabel
            font.pixelSize: 0.2*compositeInterval.height
            text: "Switch Interval"
            font.family: "Helvetica"
            anchors.top: parent.top
            anchors.right: parent.right
            color: "#FFFFFF"
        }
        Slider {
            id: compositeIntervalSet
            height: parent.height
            width: parent.width
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            from: 0
            to: 255
            stepSize: 1
            snapMode: Slider.SnapOnRelease
            Component.onCompleted: {
                compositeIntervalSet.value = myClass.composite.timeLimit
                myClass.composite.timeLimit = Qt.binding(function() { return compositeIntervalSet.value })
            }
            handle: Rectangle {
                x: parent.leftPadding + parent.visualPosition * (parent.availableWidth - width)
                y: parent.topPadding + parent.availableHeight / 2 - height / 2
                implicitWidth: parent.height*.8
                implicitHeight: parent.height*.8
                radius: parent.height*.4
                color: parent.pressed ? "#480090" : "#000000"
                border.color: "#ffffff"
                border.width: 4
                Image {
                    anchors.fill: parent
                    anchors.margins: 0.15*parent.width
                    source: "SpeedIcon.png"
                    sourceSize.height: 128
                    sourceSize.width: 128
                }
            }
        }
    }
    

  • Moderators

    @kgregory said in Slider is not a type:

    Here is a larger snip including the Item to which the Slider is a member.

    The full error is qrc:/home.qml:778:9: Slider is not a type. Line 778 is the first line that declares the Slider object.

    Is there no lines before or after it? Sometimes its due to the fact that something Slider uses is not found, as opposed to Slider itself. Can you use Slider in a standalone example or does that fail too?



  • There are 870 lines in this file, this is near the end of it. What do you mean by stand alone?

    I'm using pageloader to load different pages. Any of the ones that I use Slider in fail to load with this error. Perhaps it's something I'm doing consistently across the board, like customizing the handle?



  • So I tried switching back to Qt 5.12.0. I had to import QtQuick.Controls 2.12 instead of 2.14 in order to do so. Once I did that it, I don't have this issue again. I also tried Qt 5.14.1 with QtQuick.Controls 2.12 and that has the problem.

    I tried commenting out various parts of the Slider code and things around it to see if I could fix it. All of my pages that have slider (most of them) have his problem. One of my pages has a problem with a type other than slider. I can't tell what the two have in common.

    Anyway, I'm ok with continuing to use Qt 5.12.0, there isn't a particular reason why I need to use Qt 5.15.1 right now.


  • Moderators

    @kgregory said in Slider is not a type:

    There are 870 lines in this file, this is near the end of it. What do you mean by stand alone?

    I'm using pageloader to load different pages. Any of the ones that I use Slider in fail to load with this error. Perhaps it's something I'm doing consistently across the board, like customizing the handle?

    I meant if you make a small example that just uses Slider does it fail then, I used your snippet and it worked for me so I don't know why it is not working for you.


Log in to reply