Maximum size of QString

老子叫甜甜 提交于 2019-12-21 23:05:40

问题


I am using Qt 5.9 on Ubuntu 16.04 64-bit architecture. I had a requirement in which I need to take input from a file which can have characters in the range of 10^8. Unfortunately breaking down the file in parts and working on that is not an option as I need the entire data in the file for the operation of my code.

From what I have thought out so far I plan to store the file data in a QString(any other suggestions are welcome). What is the maximum size that QString can store in this regard? I have seen the following links but none of them provide a concrete answer:

  • Link 1
  • Link 2

Since my data falls very close to the limits defined in Link 1 of 2^30, is QString a suitable choice for this?

Note: All the data will be hexadecimal and I will need to convert the QString to a QByteArray down the line.

My other concern is if it will be able to handle that many number of characters efficiently. From what I have read Qt optimizes the string length as a means of fine tuning QString's memory usage. Will this impact the file read operation considering the huge amount of characters(in terms of time taken).

Adding a sample code for read operation:

void readData (QString file) {
    QFile f(file);
    if (!f.open(QFile::ReadOnly | QFile::Text)) break;
    QTextStream in(&f);
    QString data=in.readAll(); // alternately, this can be read line by line along with QStringBuilder
}

来源:https://stackoverflow.com/questions/46237476/maximum-size-of-qstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!