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 JSGen
for 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 directory
how 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
qmldir
file in your folder:SpiralCoreFunctions 1.0 ./SpiralCoreFunctions.qml
Your folder structure will look like this:
main.qml SpiralCoreFunctions.qml qmldir
In this case you will be able to create
SpiralCoreFunctions
object in yourmain.qml
.Another option is:
- Create folder
components
- Put
SpiralCoreFunctions.qml
andqmldir
files in this directory. - In
main.qml
addimport "./components"
Your folder structur will look like this:
components |-SpiralCoreFunctions.qml ā-qmldir main.qml
Anyway, don't forget to add all this files to your .qrc file.
- Create folder
-
@speqtr said:
Hi,
you need to add
qmldir
file in your folder:SpiralCoreFunctions 1.0 ./SpiralCoreFunctions.qml
Your folder structure will look like this:
main.qml SpiralCoreFunctions.qml qmldir
In this case you will be able to create
SpiralCoreFunctions
object in yourmain.qml
.Another option is:
- Create folder
components
- Put
SpiralCoreFunctions.qml
andqmldir
files in this directory. - In
main.qml
addimport "./components"
Your folder structur will look like this:
components |-SpiralCoreFunctions.qml ā-qmldir main.qml
Anyway, 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