QML object cannot be console.log, is it a bug?
-
QML object cannot be console.log, is it a bug?
@
import QtQuick 2.1
import QtQuick.Controls 1.0ApplicationWindow {
id: root
visible: true
width: 640
height: 480
title: qsTr("Hello World")menuBar: MenuBar { Menu { title: qsTr("File") MenuItem { text: qsTr("Exit") onTriggered: Qt.quit(); } } } Text { id: mytext text: qsTr("Hello World") anchors.centerIn: parent } Component.onCompleted: { //var textjs = {"mytext":"text`"} console.log(JSON.stringify(mytext)) }
}
@
-
Hi,
Do you get any Error ? Which Qt version are you using ?
-
Sorry, please try my updated post.
-
In this case console.log puts
@
QQuickText(0x289b6b0)
@which i think is proper.
What do you desire as output ?
You can assign an objectName to an Element and to get back you can use the same property in console.log -
Which Qt version and OS are you using?
I use Windows 7 64 bits and Qt 5.3.0 VC 2013 64bits.
My result is
"qrc:///qml/main.qml:37: TypeError: Type error" -
I use Qt 5.3.1, Ubuntu 14.04.
Sorry i didn't mention earlier, i did this:
@
console.log(mytext)
@and not stringify thing. So it prints what kind of C++ object it is.
-
Is there an simple way to print all properties of a QML object?
-
I think you can use Qt's "Meta Object System":http://qt-project.org/doc/qt-4.8/metaobjects.html to get functions, properties etc..