Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery memory leak when INSERT
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery memory leak when INSERT

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    I use postgres DB to log some actions in my system. I use QSqlQuery to make inserts. But when I run my program till the long period of time I see that my program eats lot of RAM. I use 32-bit OS Windows, but the same situation is on Linux.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Before complaining, post your code, there might be a memory leak in your code! Qt is properly tested, but off course bugs might exist.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anticross
        wrote on last edited by
        #3

        Here the method wich I call every time when need to write some data to DB. m_query is a mebber of class. @void LogRunnable::dbInsert(const sxProperties & cmd, const QVariant & parent, int type) {

        QSqlDatabase db = QSqlDatabase::database(sxDB::connection::connectionName);
        if (db.isOpen() == false) {
        printToConsole("Database is not opened...");
        if (false == checkDb(db)) {
        return;
        }
        }
        int nextCommandId = getNextIdList();

        // adding command to db
        QString newQueryStr;
        const QString dateTime = QDateTime::currentDateTime().toString(TimeTemplate::dateTime);
        if (0 != parent) {
        newQueryStr = QString("insert into %1( %2, %3, %4, %5, ) values (%6, '%7','%8', '%9', ''); ")
        .arg(sxDB::table::cmd_list)
        .arg(sxDB::cmd_list::CMD_ID)
        .arg(sxDB::cmd_list::CMD_TIME)
        .arg(sxDB::cmd_list::CMD_TYPE)
        .arg(sxDB::cmd_list::CMD_PARENT)
        .arg(nextCommandId)
        .arg(dateTime)
        .arg(type)
        .arg(parent.toString())
        .arg(sxDB::cmd_list::CMD_COMMAND)
        .arg(cmd.collectCommand());
        }
        else {
        newQueryStr = QString("insert into %1( %2, %3, %4,%8) values (%5, '%6','%7','%9'); ")
        .arg(sxDB::table::cmd_list)
        .arg(sxDB::cmd_list::CMD_ID)
        .arg(sxDB::cmd_list::CMD_TIME)
        .arg(sxDB::cmd_list::CMD_TYPE)
        .arg(nextCommandId)
        .arg(dateTime)
        .arg(type)
        .arg(sxDB::cmd_list::CMD_COMMAND)
        .arg(cmd.collectCommand());
        }

        db.transaction();
        if (false == m_query.exec(newQueryStr)) {
        printToConsole("Failed to insert argument to argument list: " + db.lastError().text());
        }
        db.commit();
        m_query.finish();
        m_query.clear();
        }@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved