When using a QMultiHash, I experienced an unexpected value returning from the function QMultiHash::size()
I went to the docs (I'm using Qt 6.2.7) and found that according to them, QMultiHash doesn't HAVE a size function. I acknowledge that I'm doing something that's outside the advertised API and I can't technically expect anything. But, still, it's a size function. I know what I expected it to do.
I used an idiomatic Qt function that exists in many Qt containers, and expected it to work. THAT'S the bug I'm reporting, I think. I recognise that the function, while public, isn't documented and thus I shouldn't use it. HOWEVER, I used it without even thinking about it; because Qt containers have a size function that I expect to tell me the size of the container.
This code snippet:
0 ("size" of newly constructed QMultiHash)
0 ("size" of newly constructed QMultiHash, after I've put a value into it using operator. THIS WAS UNEXPECTED - THERE IS SOMETHING IN THE CONTAINER. THE SIZE SURELY CANNOT BE ZERO)
5 (the value I put in, read back from the QMultihash)
1 (the "size" of the QMultiHash after I put another value into it, using insert. THIS WAS ALSO UNEXPECTED - NAIVELY, SURELY SHOULD BE 2)
5 (the first value I put in, read back from the QMultihash)
7 (the second value I put in, read back from the QMultihash)
Two values are stored in the QMultiHash, but its (undocumented) size() function says one.
QMultiHash::keys() returns a list of keys of the expected size. I can reliably figure out the actual size of the QMultiHash. That's not the problem.
The problem is that the isEmpty function and size functions for QMultiHash, while not documented, exist and can be called and return very surprising values if I've put something into the QMultiHash object using operator
It's very easy for programmers to accidentally use these functions without realising they're not documented and make no promises about what they do.
I think they should be private functions (or removed, or in some other way made impossible for us to accidentally call them) or should return the values we would expect.