I'm trying to code a traversal function for a huffman tree that will generate the code dictionary containing the binary codes for each letter in the tree. Once it hits a leaf node I want to insert the character and a QBitArray into the QMap that I pass in.

The part I am confused about is how I can build up the QBitArray before inserting it with the character into the QMap.

Here is my code for the function so far.

```
template <class CollectionType, class UnitType>
void HuffmanTree<CollectionType, UnitType>::traverse(Node* root, QMap<UnitType, QBitArray>* codes) const
{
if(root->leftChild == NULL)
{
qDebug() << "Character: " << root->data[0];
//codes->insert(root->data[0], );
}
else
{
traverse(root->leftChild, codes);
traverse(root->rightChild, codes);
}
}
```