title: Typed arrays in QML? QByteArray to JS Uint8Array back and forth interop
body: <p>Although JavaScript does seem to provide a range of type arrays for efficiently storing various width integer and real numbers, those seem to be absent in the QML implementation:</p>
  
  <pre><code>​var array = new Uint8Array // error: Expected token `}
  </code></pre>
  
  <p>I am in need of <code>QByteArray</code> interop between C++ and JS, and it is not as trivial as making <code>QByteArray</code> a metatype so it can be used in QML as a parameter - I need persistent hard copies of the data living in JS, although I will not be modifying the data from JS and will only be used in the exposed C++ API.</p>
  
  <p>I currently have a solution based on converting back and from using <code>QString</code> and Latin1 conversion, and even though it does seem to pass simple unit tests, it feels flimsy and unsafe, so I wonder if there is a more elegant and cleaner solution? Also, it is somewhat inefficient, as it would use two bytes for every byte stored in it.</p>
  
  <p>So it turned out that:</p>
  
  <ul>
  <li>as Mitch pointed out, there is a "ghost" character which messes up the code</li>
  <li>Creator's autocomplete doesn't detect Uint8Array, which reinforced my suspicion that it isn't there</li>
  </ul>
  
  <p>This code snippet confirms it is there and working:</p>
  
  <pre><code>  var array = new Uint8Array(1)
    array[0] = 257
    console.log(array[0]) // outputs 1, the expected overflow value
  </code></pre>
  
  <p>But the significant part of the question remains unanswered - how to (efficiently) interop between <code>QByteArray</code> and <code>Uint8Array</code>. The key here is efficiency as I have plenty of those interops, and I'd hate to use something as clumsy as filling in <code>Uint8Array</code> by calling JS functions from C++ one element at a time.</p>