[Qt-creator] Import QML Errors

Stenger Christian Christian.Stenger at theqtcompany.com
Tue Oct 6 07:21:58 CEST 2015


Hi Freddy,


regarding the import error: you're importing the wrong way. You don't have to import the file at all if it is located inside the same folder as your main.qml file.

So, first of all change the import to


import "qml"'


inside your main.qml.

Now, ULineEdit.qml should be imported correctly, but it has other issues to get it working.. (You will still get something like 'Element is not creatable' - I don't exactly know what you're aiming at, but at first you should replace


property Font fontEdit


by


property font fontEdit


Now you should be able to successfully import and run your code. Hope this helps.


Kind regards,

Christian

________________________________
From: qt-creator-bounces+christian.stenger=theqtcompany.com at qt-project.org <qt-creator-bounces+christian.stenger=theqtcompany.com at qt-project.org> on behalf of Freddy Martinez <freddy311082 at gmail.com>
Sent: Tuesday, October 6, 2015 6:04 AM
To: qt-creator at qt-project.org
Subject: [Qt-creator] Import QML Errors

Hello Guys...

I have 2 qml files:

main.qml and
qml/ULineEdit.qml

as you can see, I have a main.qml file at the same level with the qml folder which has a ULineEdit.qml

this is my ULineEdit.qml


import QtQuick 2.0



Rectangle {

    id: idEdit

    property double widthEdit : width

    property double heightEdit : height

    property string placeHolderText: ""

    property color underlineColor

    property color textColor

    property color placeHolderColor

    property Font fontEdit


    // underline for lineEdit

    Rectangle{

        id: underlineId

        color: underlineColor

        width: widthEdit

        height: heightEdit / 10.0

        anchors.bottom: idEdit.bottom

    }


    TextInput{

        id: textId

        font: idEdit.fontEdit

        property bool showPlaceHolder: true


        text: qsTr(placeHolderText)

        width: idEdit.widthEdit

        height: idEdit.height - underlineId.height - 2

        anchors.bottom: underlineId.top

        verticalAlignment: Text.AlignVCenter

        horizontalAlignment: Text.AlignLeft


        onTextChanged: {

            if (textId.text == "")

            {

                textId.text = idEdit.placeHolderText

                textId.color = idEdit.placeHolderColor

                textId.showPlaceHolder = true

            }


            else

            {

                textId.font = idEdit.fontEdit

                textId.showPlaceHolder = false

            }

        }


        onFocusChanged: {

            if (textId.focus == true)

            {

                if (textId.showPlaceHolder == true)

                {

                    textId.text = "";

                }

            }


            else

            {

                // checking if we have to show the placeholder or not

                if (textId.showPlaceHolder == true)

                {

                    textId.text = idEdit.placeHolderText

                    textId.color = idEdit.placeHolderColor

                }

            }

        }


    }

}



and this is my main.qml file


import QtQuick 2.3

import QtQuick.Controls 1.2

import QtQuick.Window 2.0


import "./qml"


Window {

    visible: true

    width: 640

    height: 480

    title: qsTr("Ultra4")

    color: "#F9F9F9"


    Rectangle{

        width: 100

        height: 20

        color: "black"


        ULineEdit{


            widthEdit: 100

            heightEdit: 20

        }

    }

}



the problem is that when I try to run my app, Qt Creator give the following error:

qrc:/main.qml:19 Type ULineEdit unavailable
qrc:/qml/ULineEdit.qml:4 Element is not creatable.

What is the problem ? because I can't see it...

regards

=============================================
"El tamaño de tus logros depende del tamaño de tus metas."
C++ and Qt Senior Developer
Lic. Computer Science
Buenos Aires, Argentina

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20151006/d737db70/attachment.html>


More information about the Qt-creator mailing list