PDA

View Full Version : QML's import does not work



MarkoSan
6th September 2014, 08:36
Dear Sirs and Madams!

I have following code chunk:
import QtQuick 2.3
import QtQuick.Window 2.1
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1

import "components"

ApplicationWindow
{
id: fsaWindowMain

property int fsaWindowWidth: 800
property int fsaWindowHeight: 400
property int fsaSpacingHoriz: 8
property int fsaSpacingVert: 8
property int fsaToolBarHeight: 48

visible: true

width: fsaWindowWidth
height: fsaWindowHeight

color: "black"

toolBar: fsaToolbarMain
statusBar: fsaStatusBarMain

ToolBar
{
id: fsaToolbarMain

width: parent.width
height: fsaToolBarHeight

fsaMenuItem
{
fsaMenuItemWidth: width
fsaMenuItemHeight: height
fsaMenuItemRadius: 32
fsaMenuItemText: "text1"
}
}

StatusBar
{
id: fsaStatusBarMain

width: parent.width
height: fsaToolbarMain.height
}
}Now, fsaMenuItem is declared in fsaMenuItem.qml in components subdir:
import QtQuick 2.0

Rectangle
{
id: fsaMenuItem

property int fsaMenuItemWidth: 128
property int fsaMenuItemHeight: parent.height
property int fsaMenuItemRadius: 32
property string fsaMenuItemText: ""

width: fsaMenuItemWidth
height: fsaMenuItemHeight

radius: fsaMenuItemRadius

Text
{
color: "white"
text: qsTr(fsaMenuItemText)
}

color: "black"
}And the directory hierhcary is as follows:10622Why does import clause does not import fsaMenuItem?

wysota
6th September 2014, 17:04
All QML component names need to begin with a capital letter.

MarkoSan
6th September 2014, 17:46
All QML component names need to begin with a capital letter.If I put a capital in component name, I get
Unknown Id (M14)error. Here is screenshot:10623

faldzip
7th September 2014, 06:39
But you have changed the id, not the component name. Component name is the name of the file where this component is defined. And you use that name to instantiate the object of that type.

MarkoSan
7th September 2014, 07:13
But you have changed the id, not the component name. Component name is the name of the file where this component is defined. And you use that name to instantiate the object of that type.So the filename (component name), must begin with capital?

MarkoSan
7th September 2014, 18:11
Now the code finds component, but at runtime the file cannot be found:
Starting D:\xxxxx\xxxxx\Software\fsaInteractor\bin\x86\debu g\debug\fsaInteractor.exe...
QML debugging is enabled. Only use this in a safe environment.
QQmlApplicationEngine failed to load component
qrc:/FsaQmlMain:36 Type FsaComponents.FsaMenuItem unavailable
qrc:/components/FsaMenuItem.qml:-1 File not found

Here is qml.qrc file listing:


<RCC>
<qresource lang="English" prefix="/">
<file alias="FsaQmlMain">main.qml</file>
</qresource>
<qresource lang="English" prefix="/components">
<file alias="FsaQmlMenuItem">components/FsaMenuItem.qml</file>
</qresource>
</RCC>

and here is directory listing:
10624

Why the file is not being found?

Sincerely,
Marko

wysota
8th September 2014, 06:40
Because you have aliased its name.

anda_skoa
8th September 2014, 06:51
Try to specify the URL for your main QML file as "qrc:///main.qml" instead of "qrc:/main.qml"

Cheers,
_

MarkoSan
8th September 2014, 07:13
Try to specify the URL for your main QML file as "qrc:///main.qml" instead of "qrc:/main.qml"

Cheers,
_But it is not the problem in main.qml (main.qml works fine), it is problem in the one of imported elements, FsaMenuItem.qml.

anda_skoa
8th September 2014, 13:33
But it is not the problem in main.qml (main.qml works fine), it is problem in the one of imported elements, FsaMenuItem.qml.

Yes, that was obivous.
Nevertheless can the base URL affect resolution of subsequent URLs

Cheers,
_