File Handling in QML



  • Hi,

    Is there any way to do file handling in QML using Javascript or any plugins written in C++ for this purpose ?



  • I don't think it is possible, and more over its not suggested to write business logic in JavaScript which effects your application performance.



  • You just have to code a QDeclarativeItem subclass in C++ with the methods (and the internal state information like current directory, etc.) you need and register it at runtime so it becomes accessible as a QML Element as described here:
    http://doc.qt.nokia.com/4.7-snapshot/qml-extending.html

    But as Vijay said, you should be very careful how you do it, because if you just expose a few basic file handling methods and then use javascript to code a more complex stuff calling the low level ones, you usually end up with business logic embedded on the UI side of your application.

    For example, if your QML c++ object just provides access to fopen(), fclose(), fprint() functions, you usually end up with lots of javascript code performin loops and calling those functions to decode/encode data etc.

    Better if you define a QDeclarativeItem subclass that performs the file handling operations including most of the complex stuff and then emits a signal when done or exposes a QML ListModel with the result of the operations performed.

    For example, when you change the source property in the QML Image element , the element performs lots of file operations and data conversions, but on the UI side you just get onStatusChanged signals and the UI perform a refresh of the image.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.