PDA

View Full Version : Despair



mikro
8th October 2006, 23:05
help please! i am getting crashes at a trivial point where there should be no crashes and i can't understand why. I am afraid this is going to be rather long, simply because i will have to quote some stuff, probably you can read this from bottom (where i include a trace) to top.

i have one class cMassnahme, which is a subclass of QListWidgetItem and is initiated as a singleton.

the cMassnahme-objects are created by my mainwindow (MainWindow). There can be more than one cMassnahme object with different ids which seems to work.

(listMassnahmen is a QListWidgetItem which will be parent )


void MainWindow::fillMassnahmen() {
QString sql="SELECT idMassnahme,bezeichnung FROM pMassnahmen";
QSqlQuery query(sql,db);
massnahmen.clear();

cbMassnahme->insertItem(0,"--- please choose ---");
int row = 1;
while (query.next()) {
QString id = query.value(0).toString();
QString bez = query.value(1).toString();
cMassnahme* currMass = cMassnahme::self(id,listMassnahmen);

// Fill a Combobox as well
cbMassnahme->insertItem(row,currMass->getBezeichnung());

// some QMaps to make sure i find my stuff again
massnahmen[id] = currMass;
massnahmenIDs[id] = row;
massnahmeFromID[row] = currMass;

row++;
}
}

later on i open a new window of the class ConfigWindow from MainWindow. I need a combobox that will allow me to choose between the massnahmen in this Window as well. to create this i have a very simple function:


void ConfigWindow::fillMassnahmen() {
cbMassnahmen->insertItems(0,mw->getMassnahmenContent());
}
which should work, as mw is a pointer to the mainwindow-class. and the getMassnahmenContent() looks like this:

QStringList MainWindow::getMassnahmenContent() {
QStringList list;
int allM = cbMassnahme->count();
for (int i=0;i<allM;i++) {
list.insert(i,cbMassnahme->itemText(i));
}
return list;
}

up to this point everything seems to work. now while the combobox in ConfigWindow is filled this slot is called:

void ConfigWindow::on_cbMassnahmen_currentIndexChanged ( int index) {
QLocale loc;

currentMassnahme = mw->getMassnahmeFromRow(index);
QString bez = currentMassnahme->getBezeichnung();
...

the two functions here are rather simple as well. mw is a pointer back to the MainWindow, with the function


cMassnahme* MainWindow::getMassnahmeFromRow(int row) {
return massnahmeFromID[row];
}
and the second line refering to this function:


QString cMassnahme::getBezeichnung() {
return bezeichnung;
}

now, finally, the funny part: the application crashes in the last function! DrMingw gives me this trace:

Call stack:
004D3C48 werter.exe:004D3C48 QString::QString(QString const&) qstring.h:608
...
{ if (!isNull()) *this = QString(); }
inline QString::QString(const QString &s) : d(s.d)
> { Q_ASSERT(&s != this); d->ref.ref(); }
inline int QString::capacity() const
{ return d->alloc; }
...

0043B0CC werter.exe:0043B0CC cMassnahme::getBezeichnung() massnahme.cpp:82
...
QString cMassnahme::getBezeichnung() {
return bezeichnung;
> }

float cMassnahme::getKostenNettoSumme() {
...

0045B0AB werter.exe:0045B0AB ConfigWindow::on_cbMassnahmen_currentIndexChanged( int) ConfigWindow.cpp:259
...

currentMassnahme = mw->getMassnahmeFromRow(index);
> QString bez = currentMassnahme->getBezeichnung();

leBezeichnung->setText(bez);
...

any idea what should bother the application at this point?

jacek
8th October 2006, 23:15
void ConfigWindow::on_cbMassnahmen_currentIndexChanged ( int index) {
...
currentMassnahme = mw->getMassnahmeFromRow(index);
QString bez = currentMassnahme->getBezeichnung();
...
What is the value of "index" when your program crashes? How many items there are in massnahmeFromID? How do you initialize it?

mikro
8th October 2006, 23:24
aarghss. it was so easy and once again i spend hours being blind. of course there is no reason for the program to crash where it did: the combobox will have "---please choose ---" as a first item, so index can be 0 but of course the QMap only has entries for rows that have a massnahme.
Thank you for your quick reply which got me to finally look at the right place.