Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML object cannot be console.log, is it a bug?
Forum Updated to NodeBB v4.3 + New Features

QML object cannot be console.log, is it a bug?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vincent007
    wrote on last edited by
    #1

    QML object cannot be console.log, is it a bug?

    @
    import QtQuick 2.1
    import QtQuick.Controls 1.0

    ApplicationWindow {
    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))
    }
    

    }

    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Do you get any Error ? Which Qt version are you using ?

      157

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vincent007
        wrote on last edited by
        #3

        Sorry, please try my updated post.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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

          157

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vincent007
            wrote on last edited by
            #5

            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"

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              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.

              157

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vincent007
                wrote on last edited by
                #7

                Is there an simple way to print all properties of a QML object?

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  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..

                  157

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved