Important: Please read the Qt Code of Conduct -

Qt 4.8 qml; javascript method does not work

  • Hi. I 'm trying to use javascript methods but many do not work and found me a list of methods that do work in qt 4.8. Probe with simple standard codes and so do not understand that failure

    I 'm trying to create a function that returns a string trimmed

    the chain is for example: "file///E:/texto.txt"

    I want it to be: "E:/texto.txt"

    the function to use is:

    property string texto = "file///E:/texto.txt"
    function ubicacion(x) {
        var re = x;
        var ext = re.substring(7);
       return ext

    this does not work. probe write a thousand different ways and with other similar methods. I also tried javascript basic methods but do not work .

    use "substring", "substr", "slice", "length"

    in the same code and use this code if it works:

    function extension(x) {
        var re = /(?:\.([^.]+))?$/;
        var ext = re.exec(x)[1];
        return ext

    and not know what else to try

    He added : Accomplish make it work with a normal string . but when I use another string it does not work. try using " toString(x)" but gives nullo value

    x = filePath
    (filePath from Qt.labs.folderlistmodel 1.0)

  • achieve make it work like this:

    property string archivo: null
    function ubicacion(x) {
       archivo = x;
       return archivo.substr(8);