I put some modules in a module folder. How do I import classes with the import statement when I'm in a sub folder?
This won't work, not like classes which are in packages.
modules/SomeModule.mxml
<?xml version="1.0"?>
<mx:Module>
<mx:Script>
<![CDATA[
import Fruit.Apple;
]]>
</mx:Script>
</mx:Module>
Directory:
.
|-- Fruit
|-- Apple.as
|-- Modules
|-- SomeModule.mxml
`-- application.mxml
This should work as long as the src folder is set to the above directory and the Apple class has the correct package declaration (package Fruit { ... })
Related
The following project structure is working for import a qml module:
Project structure
Project
|- modules
|- Goofy
|- qmldir
|- Donald.qml
|- project.pro
|- main.cpp
|- main.qml
|- qml.qrc
project.pro
QT += quick
SOURCES += \
main.cpp
RESOURCES += \
modules/Goofy/Donald.qml \
modules/Goofy/qmldir \
qml.qrc
QML_IMPORT_PATH = $$PWD/modules
QML_DESIGNER_IMPORT_PATH = $$PWD/modules
main.cpp
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/modules");
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import Goofy 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Donald{}
}
qmldir
module Goofy
Donald 1.0 Donald.qml
How should I modify my project to import the module from a qrc file instead of adding any single file to the resources??
Ideally I'd like to have the following pro file:
project.pro
QT += quick
SOURCES += \
main.cpp
RESOURCES += \
modules/Goofy/goofy.qrc \
qml.qrc
QML_IMPORT_PATH = $$PWD/modules
QML_DESIGNER_IMPORT_PATH = $$PWD/modules
I tried adding goofy.qrc (or Goofy.qrc) to my modules/Goofy folder with the following format:
<RCC>
<qresource prefix="/">
<file>qmldir</file>
<file>Donald.qml</file>
</qresource>
</RCC>
but it doesn't work. What should I do?
Your Goofy.rcc doesn't work because the files are not located in the used importPath. The files are next to the qrc, so no relative path is added to the specified prefix. Alter the rcc to the following to make it work:
<RCC>
<qresource prefix="/modules/Goofy">
<file>qmldir</file>
<file>Donald.qml</file>
</qresource>
</RCC>
As you already seem to understand, the qmldir file needs to be in the Goofy path for the QmlEngine to accept it. Add that to the specified import path and QmlEngine will find your module, just like it's on disk (since qrc is actually rendered as a normal filesystem)
BTW, You can check the working of relative qrc paths with the following snippet:
QDirIterator qrc(":", QDirIterator::Subdirectories);
while(qrc.hasNext())
{
qDebug() << qrc.next();
}
I'm new in gulp and I have a problem with managing hosted fonts in my website.
Does anyone know how I should write gulp task, which creates #fontface in my style.css file? (I tried to use this npm package (https://www.npmjs.com/package/postcss-font-magician#hosted) but it didn't work!)
here is my gulp task (styles.js):
var gulp = require('gulp'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
cssvars = require('postcss-simple-vars'),
nested = require('postcss-nested'),
cssImport = require('postcss-import'),
mixins = require('postcss-mixins'),
hexrgba = require('postcss-hexrgba'),
colorFunctions = require('postcss-color-function'),
fontMagician = require('postcss-font-magician')({
hosted: ['../../app/assets/fonts']
});
gulp.task('styles', function() {
return gulp.src('./app/assets/styles/styles.css')
.pipe(postcss([cssImport, mixins, cssvars, nested, hexrgba, colorFunctions,
fontMagician, autoprefixer]))
.on('error', function(errorInfo) {
console.log(errorInfo.toString());
this.emit('end');
})
.pipe(gulp.dest('./app/temp/styles'));
});
here is my css code:
body {
font-family: 'parastoo';
}
and this is my source tree:
|--app
| |-- assets
| | |-- fonts
| | | |-- parastoo.woff
| | | |-- parastoo.woff2
| |-- index.html
|-- gulp
| |-- tasks
| | |-- styles.js
|-- gulpfile.js
|-- package.json
|-- webpack.config.js
Thank you very much.
Situation:
Writing a Qt Quick application for embedded Linux system, want to use Qt translation mechnanism. Application shall select language on command coming in via RS232, currently hardcoded to "de" on a system set up for english language. Application loads various masks on command from RS232.
Problem:
Qt Quick translates only the main page (main.qml), but not the pages loaded via the Qt Loader (DEMO.ui.qml). Texts from main.qml are displayed in german, texts from DEMO.ui.qml are displayed untranslated.
I've added a "XX" prefix to all english translations (qml.en.ts), that also does not appear on the screen. So neither english nor german translations are loaded for pages loaded via the Qt Loader.
Clean build after lupdate, lrelease does not help. rm -rf build-$appname-*, build does not help.
Code:
application.cpp:
xlat=new QTranslator();
if (xlat->load(QLocale("de"), "qml", ".", ":/qml/i18n/", ".qm")) {
qDebug()<<"load translator ok";
bool ok=installTranslator(xlat);
//...
} // else error message
// ...
viewer->setSource(QUrl("qrc:/qml/main.qml"));
viewer->showFullScreen();
// ...
main.qml:
import QtQuick 2.0
Rectangle {
Text {
id: loadingMsg
text: qsTr("Loading ...")
// ...
}
Loader {
// ...
source: ""
function loadMask(aMaskId) {
// ...
setSource(gui.urlForMask(aMaskId));
}
}
// ...
}
components/SimpleButton.qml:
import QtQuick 2.0
// ...
Rectangle {
Text {
id: label
text: ""
// ...
}
property alias text: label.text
}
masks/DEMO.ui.qml:
import QtQuick 2.0
import "../components"
//...
SimpleButton {
//...
text: qsTr("Vent.")
}
//...
qml.de.ts:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="de_DE">
<!-- ... -->
<context>
<name>DEMO</name>
<!-- ... --->
<message>
<source>Vent.</source>
<translation>Belüften</translation>
</message>
</context>
<context>
<name>main</name>
<message>
<source>Loading ...</source>
<translation>Lade ...</translation>
</message>
<!-- ... -->
</context>
Renaming DEMO.ui.qml to DEMO.qml did the trick. I guess that the Linguist tools (lupdate, lrelease) and the Qt runtime environment have different ideas of how to convert a filename to a context name.
We overrode javax.faces.application.ResourceHandlerWrapper and javax.faces.application.ResourceWrapper to load static resources, for instance css files, from the file system. How can we achieve that this resource loading mechanism also takes place for resources that are referenced in the newly loaded css file from the file system?
Thanks for any help.
Use the EL expression #{resource} in the CSS file to reference them dynamically instead of using a hardcoded path like /context/resources/someLibrary/somePath/someFile.ext or something.
E.g.
.foo {
background-image: url(#{resource['someLibrary:somePath/foo.ext']})
}
.bar {
background-image: url(#{resource['someLibrary:bar.ext']})
}
.baz {
background-image: url(#{resource['somePath/baz.ext']})
}
.moo {
background-image: url(#{resource['moo.ext']})
}
which would reference
WebContent
|-- resources
| |-- someLibrary
| | |-- somePath
| | | `-- foo.ext
| | `-- bar.ext
| |-- somePath
| | `-- baz.ext
| `-- moo.ext
:
This way the JSF default resource handler will substitute them with the right /javax.faces.resource URLs which will in turn go through the resource handler as well.
The "import "Player.as" line throws the error: 1084: Syntax error: expecting rightbrace before semicolon.
package {
import "Player.as"; //ERROR
import "Card.as";
public class Game {
I was going great with Flex, until I tried to split up my code into separate files. Now I'm struggling.
Here are my files and their dependencies:
**poker.mxml**
include "fb.as";
<mx:Script source="Game.as"/>
**Game.as**
import "Player.as";
import "Card.as";
**fb.as**
**Card.as**
**Player.as**
I'm guessing Player.as and Card.as are in the same package as Game.as?
If they're in the same package, you don't need to import them. Also, import statements don't usually have the .as extension.
When importing, you don't use the file name, but the package and class, and no quotes needed:
package
{
import Player;
import Card;
public class Game {}
}
You don't actually have to import them if they're in the top level or the same package as the class you're editing, though. If your Player and Card classes are in packages other than the top level, then you need to include the package. Here's an example with some arbitrary package names that came off the top of my head:
package
{
import com.example.Player;
import com.example.deck.Card;
public class Game {}
}
In MXML, you don't include classes using the element's source parameter. You can import them in the same way, actually.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationCompleteHandler(event)">
<mx:Script><![CDATA[
import com.example.Player;
import mx.events.FlexEvent;
private var _player:Player;
//this event handler is called once the application is fully created
//and drawn for the first time.
private function applicationCompleteHandler(event:FlexEvent):void
{
_player = new Player();
}
]]></mx:Script>
</mx:Application>
import declarations come before the package, IIRC.