0

I want to read sizes information from a database table and want to store them in a map. I use visual studio 2022 with qt tools addon and qt 6.4.

The m_sizes map is a local variable in a configurationmanager class, the manager class lives as long as the program runs.

If i set the sizes manually (version 1) it works fine.

If I read the sizes from a database table (version 2) I get an error message when leaving the routine.

SetSize

void ConfigurationHandler::setSize(Sizes key, qint16 size) 
{ 
  if (!m_sizes.contains(key)) m_sizes.insert(key, size); 
  else m_sizes[key] = size; 
}

Version 1 - without database usage

void ConfigurationHandler::initializeSizes() 
{
    setSize(Sizes::DisplayHeight, 100);
    setSize(Sizes::DisplayWidth, 50);
    setSize(Sizes::DisplayEncoderWidth, 70);
    setSize(Sizes::DisplayHeaderHeight, 20);
}

Version 2 - with database usage

void ConfigurationHandler::initializeSizes() {
    QMap<QString, QString> rows;
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("c:/users/arne/workspace/trm80eplus/trm80eplus.db");
    db.open();
    QSqlQuery q = db.exec("select * from configuration_sizes");
    while (q.next() == true) rows.insert(q.value("key").toString(), q.value("value").toString());
    setSize(Sizes::DisplayHeight, rows["display_height"].toInt());
    setSize(Sizes::DisplayWidth, rows["display_width"].toInt());
    setSize(Sizes::DisplayEncoderWidth, rows["display_encoderWidth"].toInt());
    db.close();
}

Error is

Breakpoint instruction executed
A breakpoint statement (__debugbreak() statement or similar call) was executed in TRM80EPlus.exe.

Is it because the value from rows is no longer available when leaving the routine? But actually I copy the value from the database to m_sizes and no reference or?

user2377283
  • 365
  • 1
  • 2
  • 12

0 Answers0