Unsolved 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 } } }
-
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 theSlider
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 } } } }
-
@kgregory said in Slider is not a type:
Here is a larger snip including the
Item
to which theSlider
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.
-
@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.
-
@kgregory I had exactly the same problem (with many different types) moving from 5.7 to 5.15 AND the same solution (to "downgrade" the import to statement from say, "QtQtuick.Controls 2.2" to "QtQuick.Controls 2.15"). I'm concerned that the solution is more specific, because it just seems weird. Unfortunately the QML I'm migrating was written by a real QML expert, and I'm having trouble knowing with confidence that I'm understanding all the subtleties involved. Here's an example:
import QtQuick 2.7 import QtQuick.Controls 2.2 as QtControls import bacon 1.0 import bacon.controls 2.0 import bacon.theme 1.0 QtControls.ScrollView { id: root property bool frameVisible: false property alias vertical: vbar property alias horizontal: hbar clip: true padding: root.frameVisible ? Theme.getMetric('scrollbar-frame-breadth') : 0 background: Rectangle { border { color: Theme.getColor(root.activeFocus ? 'accent' : 'secondary') width: root.padding } color: 'transparent' } QtControls.ScrollBar.vertical: ScrollBar { id: vbar parent: root x: root.mirrored ? root.rightPadding : root.width - width - root.rightPadding y: root.topPadding height: root.availableHeight active: hbar.active minimumSize: Theme.getMetric('scrollbar-minimum-height') / availableHeight } QtControls.ScrollBar.horizontal: ScrollBar { id: hbar parent: root x: root.leftPadding y: root.height - height - root.bottomPadding width: root.availableWidth - (vbar.visible ? vbar.width : 0) active: vbar.active minimumSize: Theme.getMetric('scrollbar-minimum-width') / availableWidth } }
The problem is that the line number of the error refers to the alias above, which includes two references to "ScrollBar" (the thing the error says is not a type). Fortunately includes the column which includes, which suggests that it is the second reference. Anyway, like you, it makes me nervous to simply change the import from 2.2 to 2.15 even if in some cases it fixes the problem. One possibility is that the QML has never been technically correct, but that older QML compiler was more tolerant of some error and importing the import QtQuick.Controls 2.2 directive implies a more strict language policy. @AndyS My example is the whole file, but of course it doesn't include all the customization that went into our control versions. There really is an issue here.