#include #include #include #include #include #include int main(int argc, char** argv) { QCoreApplication app(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "test"); db.setHostName("host"); db.setPort(5432); db.setDatabaseName("db"); db.setUserName("user"); db.setPassword("password"); if (db.open()) { QByteArray data(500000000, 'a'); // memory leak //QByteArray data(100000000, 'a'); // no memory leak QSqlQuery query(db); query.prepare("INSERT INTO testtable(field1) VALUES(?)"); query.bindValue(0, data); try { query.exec(); } catch (const std::bad_alloc& e) { std::cerr << "std::bad_alloc: " << e.what() << std::endl; } query.clear(); db.close(); } return 0; }