Note that there are some explanatory texts on larger screens.

plurals
  1. POQt Qvariantlist conversion into javascript array unsuccessful
    primarykey
    data
    text
    <p>I'm currently create an apps in Meego using QML and JS on most of the part. and now I stumbled upon a problem. </p> <p>From javascript I want to call a C++ function to read text file, parse it, and then return an array of the parsing result. so I create a Q_INVOKABLE function called parse() and call it through javascript</p> <pre><code>function parse() { var myArray = new Array(); myArray = parser.parse("/home/user/MyDocs/angklungtext.txt") if(myArray === undefined){ console.log("null found"); } for(var i = 0; i &lt; myArray.length; i++){ console.log(myArray[i][0] + "," + myArray[i][1]) } } </code></pre> <p>and here is the parse function in C++ </p> <pre><code>QVariantList* QMLParser::parse(QString filename) { qDebug() &lt;&lt; "start debugging"; qDebug() &lt;&lt; filename; qDebug() &lt;&lt; QDir::currentPath(); QDir dir; qDebug()&lt;&lt; dir.absoluteFilePath(filename); QFile file(filename); if(!file.exists()) { qDebug() &lt;&lt; "File: " &lt;&lt; file.fileName() &lt;&lt; "tidak ditemukan"; return NULL; } if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() &lt;&lt; "Tidak dapat membuka file" &lt;&lt; file.fileName() &lt;&lt; "untuk ditulis"; return NULL; } QTextStream stream(&amp;file); QVariantList* myList = new QList&lt;QVariant&gt;; while(!stream.atEnd()) { QString line = stream.readLine(); qDebug() &lt;&lt; line.trimmed(); QStringList lineList = line.split(":"); myList-&gt;append(lineList); } file.close(); return myList; } </code></pre> <p>sadly. when I try to run it it giving a result like this</p> <pre><code>start debugging "/home/user/MyDocs/angklungtext.txt" "/home/developer" "/home/user/MyDocs/angklungtext.txt" "1:1000" "4:2000" "5:3000" "2:4000" null found file:///opt/memoryreader/qml/memoryreader/myjs.js:8: TypeError: Result of expression 'myArray' [undefined] is not an object. </code></pre> <p>looks like the C++ parse function successfully parsing the file. it can read it and it can save it into the QVariantList. but after it return the result into javascript myArray still [undefined]. is there something wrong with the conversion? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload