title: Qt - decode binary sequence from base64
body: <p>I'm trying to decode a base64-encoded string, which contains some binary data. The string sometimes contains only one character. Unfortunately, the function QByteArray::fromBase64() works only with larger input strings.</p>
  
  <p>This code works for me for larger input strings:</p>
  
  <pre><code>QByteArray text = QByteArray::fromBase64("ykw8");
  
  unsigned int val = 0;
  for(int i = 0; i &lt; text.length(); i++)
      val |= (text.data()[text.length() - i - 1] &amp; 0xff)  &lt;&lt; (i*8);
  </code></pre>
  
  <p>after that <code>val</code> contains 13257788, which is the correct data encoded in "ykw8". However, if I submit "u" as the argument of fromBase64(), the size of resulting array (<code>text</code>) is 0. The variable <code>val</code> therefore contains also 0, although it should be 46.</p>
  
  <p>I have tried padding the input string, i. e. "u==" and similar, but the size of <code>text</code> was always 0.
  So how do I get fromBase64() decode short strings properly?</p>