Hi, I've got a problem with appending data to QByteArray, sometimes it causes C++ Runtime Error...
I tried to debug, but it always fails, just shows message box with runtime error, after researching loads of code I found out that the error is bad_alloc in QByteArray

Code I used to detect error:

Qt Code:
  1. try{
  2. //my code
  3. }
  4. catch (std::exception& e){
  5. m_logger->Error("A critical error has occred. Error Code: " + QString::fromStdString(e.what()));
  6. }
  7. catch (...){
  8. qDebug() << "error"
  9. }
To copy to clipboard, switch view to plain text mode 

and also tried different ways like qDebug() << "1"; before and another one after my code ant it never showed second one so I'm really confident that the error is in that place
(I know that the way to detect doesn't look very professional, but it works )

So, lets jump to main problem...

I'm writing an app sending attachment and need to append QByteArray with data previously encoded to base64 to another QByteArray then create post request and send it to the server

Part of code:

Qt Code:
  1. QString post_request = postRequest;
  2. if(!post_request.isEmpty()){
  3. QStringList req = post_request.split("&");
  4. foreach(QString line, req){
  5. pr += "Content-Disposition: form-data; name=\"" + line.split('=')[0] + "\"\r\n\r\n";
  6. pr += line.split('=')[1] + "\r\n";
  7. pr += "--" + boundary + "\r\n";
  8. }
  9. data += pr;
  10. }
  11. data += file; //It crashes here
  12. data += "\r\n";
  13. data += QString("--" + boundary + "--\r\n").toLatin1();
  14. data += "\r\n";
To copy to clipboard, switch view to plain text mode 

"file" is QByteArray - file encoded to base64, it has no more than 20MiB

I don't understand why it crashes, as I know QByteArray can handle about 2GB of data
I also tried qbytearray.append()

Any ideas or suggestions ?
Thank You