When you do a timer or event, order is not guaranteed. That is normal.
qWait probably locks the thread. QTest doesn’t work on my appimage version for some reason, so I can’t test it myself.
If you want something to guarantee that it processes when layer changes, then:
from krita import *
app = Krita.instance()
doc = app.activeDocument()
root = doc.rootNode()
layer = doc.activeNode().clone()
layer.setName("My Copy of " + layer.name())
root.addChildNode(layer, None)
qwin = app.activeWindow().qwindow()
layerBox = qwin.findChild(QtWidgets.QDockWidget, "KisLayerBox")
layerList = layerBox.findChild(QtWidgets.QTreeView,"listLayers")
def layerChanged(selected,deselected):
print("inside: ", doc.activeNode().name())
layerList.selectionModel().selectionChanged.disconnect(layerChanged)
layerList.selectionModel().selectionChanged.connect(layerChanged)