I was digging and realized we can register singleton url from C++ but sadly no way to have a callback with engine ptr either like C++ object :-(
int qmlRegisterSingletonType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) like the int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, QObject *(*callback)(QQmlEngine *, QJSEngine *)) I would kind of need the QObject *(*callback)(QQmlEngine *, QJSEngine *) Or maybe something automatic to create a new instance per QQmlEngine* On Fri, May 8, 2015 at 9:56 AM, Jérôme Godbout <jer...@bodycad.com> wrote: > Hi, > I'm looking for some information on the behavior of the qmldir singleton > used by different QmlEngine and thread. > > Here's my current usage: > > - QmlEngine #1 > - Main Qml script > - Many component > - usage Singleton A from custom Qml module AA with pragma > SIngleton and singleton usage inside qmldir > - usage Singleton B from C++ expose module > - Instantiate a object with QmlEngine #2 and ask him to run > script > - QmlEngine #2 with it's thread > - Qml Script requested > - Many Qml Component here too > - usage of Singleton B from C++ is ok (C++ return a different > instance based on the QmlEngine). > - usage of Singleton A (make the application crash and tell me > the object inside the singleton does not belong to the proper > QmlEngine). > > My question is the following, is the QmlEngine #2 suppose to be aware of > the singleton instantiate from QmlEngine #1 under the hood (the engine #2 > does not have any parent set and is move to a specific thread, where the > engine_ is QQmlEngine and thread_ is a QThread): > > engine_->moveToThread(&thread_); > > It clearly is aware but is he suppose to? > > The sub script is running fine and allow me to do complex script running > in parallel until I I used a singleton made inside Qml script from (from > C++ ok, since they have QmlEngine* ref to give a new instance). > > Can someone shed some light on why does qmldir singleton does not get a > new instance per QmlEngine just like C++ is doing by receiving the > QQmlEngine *qml_engine, QJSEngine *js_engine as parameters to be given a > unique singleton back per engine. > > Is the fact that I create the engine 2 inside an object that belong to > engine 1 that make this singleton cross exist between both engine even if > no parenting and thread affinity have been changed? > > Is there a way to modify this behavior? > Thanks, > > P.S.: before someone ask, WorkerScript ain't cutting it in many case > (basic type only are allowed to be transfer between thread) this is why we > came up with this solution and it's working wonderfully as long as the > object can be clone and no qmldir singleton are used. Would like to get > ride of the last limitation, the first one is conceivable and awaited. > > Jerome >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest