I hadn’t really planned on posting another article this soon, but I feel I should write about the command – console.log. console.log is an extremely powerful command that is easy to forget and is possibly not widely known about. For both of those reason I am pushing this post out today. For those who don’t know what it is, console.log() is a command that will not effect your program, but will spit information out to you at the bottom of QtCreator. This gives you the ability to see what is going on behind the scenes.
I was recently working on a drag with a rectangle that had some math involved. I thought for sure I had the equation written perfectly, but sadly what I was trying to do wouldn’t work. The odd thing to me though was the program wasn’t throwing any errors. OK I have no errors yet it isn’t working. Now what do I do? Then I remembered console.log(). I stuck this into my code within a MouseArea and found immediately what my problem was.
This told me the X coordinate of my mouse while I moved it around after pressing in the MouseArea. Of course after I did this I saw my problem and fixed it. I would have been chasing my tail for hours if I hadn’t remembered console.log().
The other reason for posting this is because a fellow QML programmer sent me over a sample of his code that he had written. There was a huge block of code in it that I couldn’t understand why it was there and what it was doing. When I asked him what it was there for he replied that it was just a popup box with information so he knew what was going on. Maybe he knew about console.log() and wanted the popup, or maybe he has never even heard of console.log(). There was a comment on my last post about there not being great documentation for QML, and I agree. Some of it is very sketchy. Because of that, console.log() could easily be over looked for a long time by someone just starting to write in QML and QtCreator.
If you already knew about console.log() I am sorry to have wasted your time, for that is all this post was about. If this article helps at least one person, then it was worth my time to write it.Comments: 1 Tags: