Qml doesn't allow javascript singletons?
-
wrote on 13 Mar 2020, 03:42 last edited by
I appears as though javascript files are executed in a separate context each time they are imported. This appears to make it impossible to store singleton objects at the top-level scope for the file. Is there any way to accomplish this?
Thanks!
-
I appears as though javascript files are executed in a separate context each time they are imported. This appears to make it impossible to store singleton objects at the top-level scope for the file. Is there any way to accomplish this?
Thanks!
wrote on 13 Mar 2020, 06:57 last edited by@patrickkidd said in Qml doesn't allow javascript singletons?:
Is there any way to accomplish this?
I think what you are looking for is pragma Singleton
-
I appears as though javascript files are executed in a separate context each time they are imported. This appears to make it impossible to store singleton objects at the top-level scope for the file. Is there any way to accomplish this?
Thanks!
-
@patrickkidd said in Qml doesn't allow javascript singletons?:
Is there any way to accomplish this?
I think what you are looking for is pragma Singleton
wrote on 13 Mar 2020, 13:18 last edited by@KroMignon said in Qml doesn't allow javascript singletons?:
I think what you are looking for is pragma Singleton
Thanks, but that is for singleton Qml components not Javascript files.
@LeLev said in Qml doesn't allow javascript singletons?:
@patrickkidd hi
https://doc.qt.io/qt-5/qtqml-javascript-resources.html#shared-javascript-resources-librariesThat was what I was looking for. However, of my 7 or so qml files that import this (all loaded in a different
QQuickWidget
), the top-level code is still being executed twice. That's better than the 7 times it was executed before, but it should only be executed once. AllQQuickWidget
instances are using the sameQQmlEngine
so I'm not sure what's going on here. -
@KroMignon said in Qml doesn't allow javascript singletons?:
I think what you are looking for is pragma Singleton
Thanks, but that is for singleton Qml components not Javascript files.
@LeLev said in Qml doesn't allow javascript singletons?:
@patrickkidd hi
https://doc.qt.io/qt-5/qtqml-javascript-resources.html#shared-javascript-resources-librariesThat was what I was looking for. However, of my 7 or so qml files that import this (all loaded in a different
QQuickWidget
), the top-level code is still being executed twice. That's better than the 7 times it was executed before, but it should only be executed once. AllQQuickWidget
instances are using the sameQQmlEngine
so I'm not sure what's going on here.wrote on 17 Mar 2020, 11:57 last edited bysorry i forgot to answer
@patrickkidd said in Qml doesn't allow javascript singletons?:executed twice
I did the test couple of days ago and the code in my js file is executed only once.
How do you import the file ? -
sorry i forgot to answer
@patrickkidd said in Qml doesn't allow javascript singletons?:executed twice
I did the test couple of days ago and the code in my js file is executed only once.
How do you import the file ?wrote on 17 Mar 2020, 18:52 last edited by@LeLev
@LeLev said in Qml doesn't allow javascript singletons?:
sorry i forgot to answer
@patrickkidd said in Qml doesn't allow javascript singletons?:executed twice
I did the test couple of days ago and the code in my js file is executed only once.
How do you import the file ?I import the file from four different qml files, all do this:
import 'js/Global.js' as Global
-
@LeLev
@LeLev said in Qml doesn't allow javascript singletons?:
sorry i forgot to answer
@patrickkidd said in Qml doesn't allow javascript singletons?:executed twice
I did the test couple of days ago and the code in my js file is executed only once.
How do you import the file ?I import the file from four different qml files, all do this:
import 'js/Global.js' as Global
wrote on 17 Mar 2020, 19:55 last edited by@patrickkidd can you make a simple project that replicates this behavior ?
1/7