enums (pure QML) in main.qml not accessable?
-
I want to use "pure qml" enums in my main.qml file. According to the docs, "Values are referred to via <Type>.<EnumerationType>.<Value> or <Type>.<Value>."
I have created my enum set in the main.qml, but I cannot access it:
import QtQuick 2.15 import QtQuick.Controls 2.15 ApplicationWindow { id: mainWin enum PageType { FACE_PAGE, SHOW_FOLDER_PAGE, SETTINGS_PAGE } property int test1: Main.PageType.FACE_PAGE property int test2: mainWin.PageType.FACE_PAGE property int test3: ApplicationWindow.PageType.FACE_PAGE (...)
The test1 property gives a ReferenceError: Main is not defined error
The other properties give a TypeError: Cannot read property 'FACE_PAGE' of undefined errorHow can I reference my enums?
-
@SeDi I think this might be unsupported, since usually the first
<type>
is the same as filename. In your case it'smain.qml
which starts with a lowercase letter so QML engine won't accept it I guess. But just in case, try this:property int test4: mian.PageType.FACE_PAGE property int test5: mian.FACE_PAGE
If all fails - you'll have to declare your enum in a different QML file, sorry.
-
@sierdzio Many thanks for answering. Unfortunately you seem to be right with this being unsupported. But actually it was much easier to re-structure my project than I had thought. Used in the proper way (== not in main.qml) enum works well by now. Would be interesting to know, if internally main.qml goes by any TypeName, thus making it referenceable. Perhaps I'll ask this in the #interest list, but for now I am settled.
-