how we can import a file qml in other file qml?
-
i import a file.js (java script)in my qml according below;
import "file.js" as JSGenfor js file it wroks correctlly
when i want to add a file.qml in the same directory file js according below;import "qrc:///SpiralCoreFunctions.qml"or
import "SpiralCoreFunctions.qml"it retrun errors in below:
qrc:///main.qml:11:1: "SpiralCoreFunctions.qml": no such directoryhow can i solve my problem?thanks for reply
-
Hi you need not import it if it is in the same directory.
just instantiate by its filenameexample
import QtQuick 2.0
Clock.qml
Item {
id : clock
property alias city: cityLabel.text
property real shift
width: {
if (ListView.view && ListView.view.width >= 200)
return ListView.view.width / Math.floor(ListView.view.width / 200.0);
else
return 200;
}
}
you can instantiatein main.qml
by Clock { city: "Bangalore"; shift: 5} -
i want to define some function in file.qml and i use method of these in new file qml ,main.qml
i test in Qt 5.2 and i write the name file qml in same directory,but i doesn't work.!!!!your idea don't work!
-
Hi,
you need to add
qmldirfile in your folder:SpiralCoreFunctions 1.0 ./SpiralCoreFunctions.qmlYour folder structure will look like this:
main.qml SpiralCoreFunctions.qml qmldirIn this case you will be able to create
SpiralCoreFunctionsobject in yourmain.qml.Another option is:
- Create folder
components - Put
SpiralCoreFunctions.qmlandqmldirfiles in this directory. - In
main.qmladdimport "./components"
Your folder structur will look like this:
components |-SpiralCoreFunctions.qml └-qmldir main.qmlAnyway, don't forget to add all this files to your .qrc file.
- Create folder
-
Hi,
you need to add
qmldirfile in your folder:SpiralCoreFunctions 1.0 ./SpiralCoreFunctions.qmlYour folder structure will look like this:
main.qml SpiralCoreFunctions.qml qmldirIn this case you will be able to create
SpiralCoreFunctionsobject in yourmain.qml.Another option is:
- Create folder
components - Put
SpiralCoreFunctions.qmlandqmldirfiles in this directory. - In
main.qmladdimport "./components"
Your folder structur will look like this:
components |-SpiralCoreFunctions.qml └-qmldir main.qmlAnyway, don't forget to add all this files to your .qrc file.
@speqtr said:
Hi,
you need to add
qmldirfile in your folder:SpiralCoreFunctions 1.0 ./SpiralCoreFunctions.qmlYour folder structure will look like this:
main.qml SpiralCoreFunctions.qml qmldirIn this case you will be able to create
SpiralCoreFunctionsobject in yourmain.qml.Another option is:
- Create folder
components - Put
SpiralCoreFunctions.qmlandqmldirfiles in this directory. - In
main.qmladdimport "./components"
Your folder structur will look like this:
components |-SpiralCoreFunctions.qml └-qmldir main.qmlAnyway, don't forget to add all this files to your .qrc file.
your idea don't work,same before errors
- Create folder
-
Import statements for qml files omit the name of the file itself. Either import a directory or a namespace.
-
i want to use qml as a class in my app,
my result is that :we should answer this if we cannot use qml for define new class,with method and property??????
we when use js file we can create new class with method and property but with qml i could n't create a class and property and method. so my question is reformed in new post.goodluck