[Interest] QQmlEngine: Illegal attempt to connect to PlatformShim(0xb9b2fb58) that is in a different thread than the QML engine QQmlApplicationEngine(0xa17e1494.

Jason H jhihn at gmx.com
Tue Dec 6 17:11:55 CET 2016


I'm still stuck. I don't know how to do this.

To recap: main.cpp make a singleton called platformShim and adds it as a property to the QQmlEngine.
Then later when trying to use a Connections element to provide a signal handler I am told
QQmlEngine: Illegal attempt to connect to PlatformShim( that is in a different thread than the QML engine.

However both of these were created in main().

QQmlApplicationEngine engine;
PlatformShim *shim = PlatformShim::instance();
engine.rootContext()->setContextProperty(QStringLiteral("platformShim"), shim);

I don't know how that error message is correct, or how to work around it.

Any help is appreciated.

> Sent: Friday, December 02, 2016 at 3:02 AM
> From: "Kristoffersen, Even (NO14)" <Even.Kristoffersen at Honeywell.com>
> To: "Qt Interest" <interest at qt-project.org>
> Subject: Re: [Interest] QQmlEngine: Illegal attempt to connect to PlatformShim(0xb9b2fb58) that is in a different thread than the QML engine QQmlApplicationEngine(0xa17e1494.
>
> The singleton one requires QML to be able to create the instance and own it doesn't it?
> 
> I'd switch to qmlRegisterUncreatableType()
> 
> 
> -Even
> 
> -----Original Message-----
> From: Interest [mailto:interest-bounces+even.kristoffersen=honeywell.com at qt-project.org] On Behalf Of Jason H
> Sent: 1. desember 2016 23:46
> To: Jason H <jhihn at gmx.com>
> Cc: Qt Interest <interest at qt-project.org>
> Subject: Re: [Interest] QQmlEngine: Illegal attempt to connect to PlatformShim(0xb9b2fb58) that is in a different thread than the QML engine QQmlApplicationEngine(0xa17e1494.
> 
> Still having issues... But made some "progress"
> So I changed to using qmlRegisterSingletonType<PlatformShim>("PlatformSupport", 1, 0 "PlatformShim", &getPlatformShim) However when I do I get 1 of 2 errors:
> 1. Element is not creatable:  when trying to declare a signal handler like PlatformShim { onPushNotificationReceived; {} } 2. Non-existent attached object: when trying to declare a signal handler (in QML) PlatformShim.onPushTokenReceived: { }
> 
> I also added:
> QObject *getPlatformShim(QQmlEngine *engine, QJSEngine *scriptEngine) {
> 	Q_UNUSED(engine)
> 	Q_UNUSED(scriptEngine)
> 
> 	return PlatformShim::instance();
> }
> 
> and
> import PlatformSupport 1.0 to the QML 
> 
> > Sent: Thursday, December 01, 2016 at 4:45 PM
> > From: "Jason H" <jhihn at gmx.com>
> > To: "Qt Interest" <interest at qt-project.org>
> > Subject: [Interest] QQmlEngine: Illegal attempt to connect to PlatformShim(0xb9b2fb58) that is in a different thread than the QML engine QQmlApplicationEngine(0xa17e1494.
> >
> > I get that error when:
> > main.cpp:
> > PlatformShim *shim = PlatformShim::instance(); 
> > engine.rootContext()->setContextProperty(QStringLiteral("platformShim"
> > ), shim);
> > 
> > In a QML file:
> > Connections {
> > 	target: platformShim
> > 	onPushTokenReceived: {
> > 		pushToken = token
> > 	}
> > }
> > 
> > I thought Connections were ok across threads?
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
> > 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> 



More information about the Interest mailing list