When I import qml from qrc (which place in different directory from ) it's compile and work fine.
But when Qt Creator don't recognize imported component and don't hightlight this.
This's code:
import QtQuick 2.0
import "qrc:/qml_libs/ApplicationContainer"
Item
{
id: root_object
width: 300
height: 200
ApplicationContainer {
width : parent.width
height: parent.height
}
}
#Aleus, your way of doing thing is little bit tricky. I can't find any information of such kind importing in official documentation (please, take a look at Importing statements in Qt 5.2, QML. Also, take a look at QML Best Practices: Coding Conventions
First of all, check weather your file ApplicationContainer really has no extension (I mean .qml)
To make QtCreator recognize imported component do next things:
Add your qml file to .pro file in section OTHER_FILES like this:
OTHER_FILES += qml_libs/ApplicationContainer
AND/OR place statement for importing whole directory to your qml file, like:
import "qml_libs" as MyLibs
...
MyLibs.ApplicationContainer { ... }
Hope it helps!
Related
I wasn't able to create and use a QML component library by following the fragmented parts of tutorials and Qt documentation, so I'm just gonna ask somebody to answer it all at once.
I want to create a single file (located in /usr/lib/project/components.rcc), that will include all components in ~/Project/src/components/ and their child components located in ~/Projects/src/components/insertparentcomponentname/. I want to be able to use those components in normal QML code.
The question is, how can I create this file and how can I import components in it to use in QML?
( Using Qt Quick 2.0 and C++ with CMake on Arch Linux )
I have a problem:
I need to use DropShadow effect from QGraphicalEffects (which deleted in qt6) in my app.
How I can do it or replace it?
You can still import GraphicalEffects from the Qt5Compat module:
import Qt5Compat.GraphicalEffects
However you first have to install the Qt5Compat module from the Qt installer, which long term might not be what you want in new code as it is going to go away eventually.
I hope the question is phrased properly, for I do not understand full what is happening in my application. I am currently trying to implement a custom version of QGroundControl and one of the things I am trying to do is replace the virtual joystick with a slider to control the yaw and pitch independently of a combined joystick via sliders.
I have created a custom qml file named "CustomHorizontalSlider.qml" and have placed it in this first image and have made sure that the file path is correct in Visual Studio Code: QtCreator Path:
I also have added the file to the custom.qrc and craeted a qmldir. Along with that I have used the updateqrc.py to make sure that the custom files are up to date: custom.qrc:
This is the error that I get when attempting to use that qml file now. Alongside here is the code if it is relevant: Error Message:
Import at the top:
Code changed to green:
Lastly, when I attempt to remove the import the module is no longer green.
Try importing as follows
import [path_to_dir] as MyControl
Example:
import "../../controls" as MyControl
And then you can use the alias to define elements (MyControl.[Name])
Example
MyControl.MyCustomButton
{
...
}
When working on a small qml project I found this behavior and I am not sure if I am doing anything wrong or if this is just how it is.
I created a simple test file Test.qml along with the main.qml and main.cpp
import QtQuick 2.0
Item {
width: 212
height: 212
Image {
id: image
x: 0
y: 22
width: 212
height: 168
source: "images/PaperSpeed.png"
fillMode: Image.PreserveAspectFit
}
}
The image linked in source above
shows the actual image in designer
but fails to show the image when running
I go ahead and change the source to the qrc URL:
source: "qrc:/img/images/PaperSpeed.png"
but now it fails to show up in designer
and instead shows up when running
What I find even weirder The image does show up in designer when on the Test.qml file but does not show up in designer when on the main.qml file for both source cases
my .pro file:
QT += quick
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
and the qrc file:
<RCC>
<qresource prefix="/">
<file>Thermostat.qml</file>
<file>main.qml</file>
<file>Test.qml</file>
</qresource>
<qresource prefix="/img">
<file>images/PaperSpeed.png</file>
</qresource>
</RCC>
This did seem to happen out of no where when I tried to import a new module like QtQuickContols eventually got rid of it but the problem persisted.
I have tried messing around with the QML emulation layer and moving the files around within the qrc. Anyone have any ideas as to what I can try or what may be going on?
Sorry in advance for any formatting issue!
I had same issue. It solves if i add an image to window.
Check the exaple below. I have same result if i remove test image from window.
For anyone still looking at this, what worked for me is separating the UI elements into a .ui.qml and the backend logic into a .qml file. This does a better job at loading UI elements and pictures when the .ui.qml file is opened in designer.
I'm pretty new to QtCreator, my issue is that I'm not able to see QML Custom Components.
For example if you import QtQuick.Controls 1.5 you see under QML types:
- Qt Quick - Controls.
So far I have created my personal set of components, here is the folder structure:
the components qmldir is done in that way:
# qmldir
module components
Header 1.0 Header.qml
Footer 1.0 Footer.qml
CentralPage 1.0 CentralPage.qml
GenericButton 1.0 GenericButton.qml
ProgressBarCustom 1.0 ProgressBarCustom.qml
than for example in the LandingPageFrom.ui.qml
import QtQuick 2.6
import QtQuick.Controls 1.5
import QtQuick.Layouts 1.3
import components 1.0 as Components
Components.CentralPage {
pageName: "landingPage"
id: landingPage
width: 800
height: 1056
property alias aButton: aButton
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
And is compiling and showing fine but inside the Designer nothing is showing as aspected, I only see .qml that are in the same directory but not the ones in components directory:
this is what I have done in the .pro and in the main.cpp
QML_IMPORT_PATH += $$PWD/resources/common/ui
QML_DESIGNER_IMPORT_PATH += resources/common/ui
main.cpp
QQmlApplicationEngine engine;
engine.addImportPath("qrc:///ui");
engine.load(QUrl("qrc:///ui/main.qml"));
What is strange is that only the designer is not able to see the components, but the QML code is able, what I'm missing here?
Not sure if you already solved your issue, but try steps 4 and 5 here:
http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
That made it work for me, although I had some issues with the metainfo file. You can just use this guys metainfo file as an example(or look at the one the Qt docs referenced in the instructions above): https://forum.qt.io/topic/56207/how-to-load-custom-qml-controls-into-the-qml-designer/2
Just make sure you put the designer folder where your module qmldir is located and the metainfo file goes in there. Probably named components.metainfo judging by the module name, not sure if that matters.