PDA

View Full Version : QComboBox crashes my application



powlee
5th April 2012, 13:13
Hi,

I have a little bit of trouble with my application crashing while filling a combo box.



gameLabel = new QLabel(tr("Spielname:"));
gameCombo = new QComboBox();

connect(gameCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(loadGameInfo(int)));

QSqlTableModel *games = new QSqlTableModel();

games->setTable("games");
games->setSort(1, Qt::AscendingOrder);
games->select();

qDebug() << "LoadGameDialog: Row Count";
qDebug() << games->rowCount();

for (int i = 0; i < games->rowCount(); ++i) {

QSqlRecord r = games->record(i);

qDebug() << "LoadGameDialog: name ";
qDebug() << r.value("name").toString();
qDebug() << "LoadGameDialog: id_games";
qDebug() << r.value("id_games");

gameCombo->addItem(r.value("name").toString(), r.value("id_games"));

qDebug() << "Item added to combo box";

}


I'm not even sure if the addItem() function is the problem since it worked fine till now. But the commandline output lead me to the conclusion that the crash is caused by the addItem() function.

Here is the Console



Starte E:\Workspace\MASA\trunk\MASA-build-desktop\debug\MASA.exe...
[Main] Cannot load translation file
[DbConnection] DB Connection "qt_sql_default_connection" established
Enter MainWindow::loadGame
before new dialog
LoadGameDialog: Row Count
72
LoadGameDialog: name
"20120207-TestKameraeinstellungUSZ"
LoadGameDialog: id_games
QVariant(int, 73)
E:\Workspace\MASA\trunk\MASA-build-desktop\debug\MASA.exe beendet, Rückgabewert -1073741819

Lykurg
5th April 2012, 13:34
That is not how you normally debug. See the backtrace to identify what really crashes the application. I bet it is not the addItem! What is it: You have a connect statement before you fill the box, thus the connection is established after you add a item, so loadGameInfo() is called. Look there for the crash!

powlee
5th April 2012, 15:57
Thx for the info, it seemed really wired to me that this function would crash. Unfortunatly my debugger is not working atm, I have some issues with other librarys not beeing built with the same compiler. Hope to fix that soon. Anyways thx for the hint.