always tips "Expected token :"
Unsolved
QML and Qt Quick
-
When I used the code below.it always occured that "expected token :"(heres the onCompleted :)
I dont know why.how to solve this.Component.onCompleted:{ sendMsg.connect(msgProxy.onSendMsg) }
-
@nicker-player
you give very little information, for example what is sendMsg ?assuming the following:
Item { id: root // Assuming sendMsg is a signal and msgProxy is an object with a slot onSendMsg signal sendMsg(string message) Component.onCompleted: { root.sendMsg.connect(msgProxy.onSendMsg) } // Example of emitting the signal function triggerSendMsg() { sendMsg("Hello, World!") } }
than it should work just fine, maybe there's a typo somewhere above the onCompleted?
btw, more commonly used is this approach:
Item { id: root // Assuming sendMsg is a signal and msgProxy is an object with a slot onSendMsg signal sendMsg(string message) // Define the signal handler directly onSendMsg: { msgProxy.onSendMsg(message) } }
-
@J-Hilk
I think it may be the space problem.
When I added the space after the part of the "Component.onCompleted:" ,the error seemed disappeared.So is it possible that the space caused the problem? -
space is usually irrelevant, especially behind an assignment
: