Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML import style file from subdirectory

Tags:

qt

qml

qtquick2

I have a problem with importing style files from a subdirectory.

This is the concerning section in my *.pro file:

QML_IMPORT_PATH = \
src/gui/qml/views/startview/ \
src/gui/qml/views/createlocalgameview/ \
src/gui/qml/views/ \
src/gui/qml/components/styles/ \
src/gui/qml/components/ \
src/gui/qml/js/

For example i have a file MyTextFieldStyle.qml placed in src/gui/qml/components/styles/:

TextFieldStyle {
    [...]
}

and i have a file TextArea.qml placed in src/gui/qml/components/:

Item {
    [...]
    TextField {
        id: textField
        style: MyTextFieldStyle {}
    }
    [...]
}

Now i get this error:

TextArea.qml: MyTextFieldStyle is not a type

If i put the MyTextFieldStyle.qml in the same directory like TextArea.qml (src/gui/qml/components/) it works fine. But i have many components and many styles and so i want to seperate them to have a better overview. Is there any way i can get this working?

like image 869
fhammer Avatar asked Jan 20 '26 02:01

fhammer


1 Answers

It should be enough putting at the top of the file an import statement with relative paths.

In your example, you can use import './styles'.

As stated in the comments, QML_IMPORT_PATH is not meant to solve that problem.

like image 51
skypjack Avatar answered Jan 21 '26 18:01

skypjack