Are you using QML because you want to use QML or because the snippet you found uses QML? Because what you are trying to do right now yields little sense.
Are you using QML because you want to use QML or because the snippet you found uses QML? Because what you are trying to do right now yields little sense.
I have little knowledge regarding C++ (or C itself) although I know how to program in Java. I'm required by my professor to come up with an application using the QT platform and that is why I'm using this kind of approach.
I've read tutorials regarding QML and by seeing these tutorials, it is possible to create a simple game with the use of only QML and Javascript. The reason why I'm using a bit of C++ is because of the fact that I have to retrieve data from the text file (according to my professor ).
But why are you calling javascript code from C++ code? Shouldn't it be the other way round?
The only reason why I utilized C++ is just to retrieve values from the text file because based from research, Javascript isn't allowed to do that. After retrieving the lines from my text file, what I plan to do is let the Javascript handle the logic.
The only way I saw how this would be possible is if I used the QMetaObject thing that I saw in the QT documentation.
If what you're saying is that I should call a C++ function using Javascript, then my answer to that is I have no clue on how to do it.
EDIT:
If ever you can suggest anything easier to do besides what I've tried, I would really appreciate it.
Last edited by bmn; 9th August 2011 at 13:23.
You clearly have issues with designing the program. If your game is driven by javascript then the whole control is also in hands of javascript. The C++ code is only required to retrieve some data so when the right time comes you only need to call a C++ function and when it returns with the data you need, simply use the data. So the real task is to expose a C++ function/method to QML environment and the docs have examples of doing that.
I will try that. Thank you.
The reason why I structured mine in such a manner is that once the application is opened, I want all lines of the text file automatically retrieved by the C++ then processed by the Javascript.
I will read about it on the QT site and post here again.
EDIT:
Seeing that my poorly constucted method works, I would, for now, just want to know why I'm receiving a TypeError such as this whenever I try to manipulate the array (formerly the QStringList from the .cpp file) which contains the data from the text file that was passed to the javascript function using the QMetaObject method.Qt Code:
TypeError: file:///C:/Users/MYCOMP/Qt/Projectproj-build-desktop/qml/Projectproj/main.qml:65: TypeError: Result of expression 'anArray' [undefined] is not an object.To copy to clipboard, switch view to plain text mode
No idea, I don't really want to analyze code that's inherently broken. Apparently you're accessing a non-object as an object.
Bookmarks