Solved Trouble with Connections
-
Yes, just the names are different.
-
Also, I can see using your method, but I have no clue how I would get to the QML object
-
@Jpraccio
Hi
I just tested the sample project and it worked.. :)
So there must be something a little bit off some place in your code or something else.Test project
https://www.dropbox.com/s/2ixu3sx172e97rm/untitled54.zip?dl=0 -
Have you registered it? For cpp instanced objects I register mine with:
qmlRegisterUncreatableType<T>
http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableType
-
I have it able to receive the signal if I put the connection in the top level Window qml. The qml object that needs the signal is nested a bit down in the hierarchy. Is this a know behavior?
-
So it seems like nothing is received down the hierarchy from the main window. I have used the Connections inside my Window qml and it's triggered fine. Trying to pass a signal from the Window down to the Component using QML and a Connection object inside the Component fails.
So the components are inside a stack view. They are Component classes that contain a rectangle. The signal needs to happen within these components. Don't know if it matter, but these are not the initialItem of the StackView. I can get some code together if desired.
-
@Jpraccio I think, my knowledge is limited here, that that behaviour depends heavly on how you marry your cpp class and your qml root file.
if for example you use
qmlRegisterType<MyClass>("MyClass",1,0, "mClass");
than you can create an instande in each qml file you import myclass in, and can use Connect and signal slots there easily enough.If you create it as a fixed class and register it as a rootContext() / ContextProperty than you should be able to access it everywhere in your qml files.
//main.cpp MyClass mClass; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("MyClass", &mClass); //any qml file Connections{ MyClass.onMySignal: console.log("SIGNAL!!!") } //The actual signal in MyClass is named: mySignal //I believe the "on" prefix is needed
-
I have the c++ class working at this point, I can send a signal to the window qml. Now trying to send a signal into the qml objects from the window. It seems these specific qml components just can't receive them. It looks like this:
// Window qml Window { id: mainWindow signal mySig() Connections { target: myCpp onAction: { // this works mySig() } } StackView { initalItem: itemA ItemA { // this has a connection that works } ItemB { // this won't receive the above signal } } } // ItemB qml Component { Rectangle { Connections { target: mainWindow onMySig: { // nothing happens here // regardles of using the cpp signal or the qml signal } } } }
-
I made some changes that forced the stack view to transition and got a new error:
QQmlEngine: Illegal attempt to connect to Chord(0x112847200) that is in a different thread than the QML engine QQmlApplicationEngine(0x7ffeefbfe1e0.
Is it possible this is a threading issue of some sort? I am not intentionally spawning any threads myself
-
Solved by pushing ItemB onto the stack view.