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

Custom type reference fails with <customControl> is not a type. Why?



  • Hi all. New to Qt Quick and QML. Following a tutorial in a book, but it's failing and I don't know why.

    I have two QML files...

    MyToolbar.qml:

    import QtQuick 2.12
    
    Rectangle
    {
    	color: "gray"
    	height: 50
    
    	Rectangle
    	{
    		id: purpleRectangle
    		width: 50; height: parent.height
    		color: "purple"
    		radius: 10
    	}
    
    	Text
    	{
    		anchors.left: purpleRectangle.right
    		anchors.right: parent.right
    		text: "hello there."
    		font.pointSize: 30
    	}
    }
    

    and then main.qml

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Layouts 1.12
    
    Window
    {
    	visible: true
    	width: 640; height: 480
    
    	Rectangle
    	{
    		width: 200; height: 200
    		color: "red"
    	}
    
    	MyToolbar
    	{
    		id: myToolbar
    		width: parent.width
    	}
    
    	RowLayout
    	{
    		anchors.top: myToolbar.bottom
    		anchors.left: parent.left
    		anchors.right: parent.right
    		anchors.bottom: parent.bottom
    	}
    }
    

    Both files are in the project file. This fails with

    W libgallery-mobile.so: QQmlApplicationEngine failed to load component
    W libgallery-mobile.so: qrc:/main.qml:16 MyToolbar is not a type
    

    I don't see anything missing from what the book shows. Any ideas? Thanks!

    Additional note: This looks a bit suspicious, with MyToolbar.qml not under Resources. But I don't know how this folder is populated:

    0_1560976291607_Screen Shot 2019-06-19 at 1.29.27 PM.png



  • 0_1560976409147_fd419141-ffb1-45a2-bcbf-72e59738b259-image.png



  • @Nifiro Thanks for the reply. I had tried that at the Resources level, but got a blanket "Couldn't add..." error with no explanation. Also tried dragging, which doesn't work.

    Any idea why Qt Creator lets you create QML files and then adds them to a "QML" folder but not to the resources?


Log in to reply