What is the maximum length of string that QString object can hold?



  • I mean how many characters we can assign at once to Qstring object?



  • @QString::size ()@ return int value, so I think, length limit is maximum integer value.

    UPD: Of course, if you have enough memory



  • As far as I remember it is 2^30.



  • Ya I was also thinking like that. Thank's ...........



  • @Lucas, not guarantied for 64 bit arc



  • I have to admit that this piece of information dates back where 64 bit didn't really matter. However, you shouldn't rely on that you can store more than 2^30 in a QString, because usually you can't - even on 64 bit architectures.



  • 2^30 is 1073741824 characters, but QString being UTF16, that means a memory usage of 2.147.483.648 bytes, plus some additional bytes around that. For a single piece of data in your application. That's 2 GB worth of data, if I'm not mistaken. Not the best idea to keep that in a single block of memory, and then I am not even talking yet of temporaries that might also be in memory at the same time (like a byte array of the same size from a file you just read, for instance).

    To summarize: if you find yourself wondering about reaching this limit, you had better start wondering about your design at a more fundamental level.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.