Results 1 to 3 of 3

Thread: Despair

  1. #1
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Despair

    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 )

    Qt Code:
    1. void MainWindow::fillMassnahmen() {
    2. QString sql="SELECT idMassnahme,bezeichnung FROM pMassnahmen";
    3. QSqlQuery query(sql,db);
    4. massnahmen.clear();
    5.  
    6. cbMassnahme->insertItem(0,"--- please choose ---");
    7. int row = 1;
    8. while (query.next()) {
    9. QString id = query.value(0).toString();
    10. QString bez = query.value(1).toString();
    11. cMassnahme* currMass = cMassnahme::self(id,listMassnahmen);
    12.  
    13. // Fill a Combobox as well
    14. cbMassnahme->insertItem(row,currMass->getBezeichnung());
    15.  
    16. // some QMaps to make sure i find my stuff again
    17. massnahmen[id] = currMass;
    18. massnahmenIDs[id] = row;
    19. massnahmeFromID[row] = currMass;
    20.  
    21. row++;
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. void ConfigWindow::fillMassnahmen() {
    2. cbMassnahmen->insertItems(0,mw->getMassnahmenContent());
    3. }
    To copy to clipboard, switch view to plain text mode 
    which should work, as mw is a pointer to the mainwindow-class. and the getMassnahmenContent() looks like this:
    Qt Code:
    1. QStringList MainWindow::getMassnahmenContent() {
    2. int allM = cbMassnahme->count();
    3. for (int i=0;i<allM;i++) {
    4. list.insert(i,cbMassnahme->itemText(i));
    5. }
    6. return list;
    7. }
    To copy to clipboard, switch view to plain text mode 
    up to this point everything seems to work. now while the combobox in ConfigWindow is filled this slot is called:
    Qt Code:
    1. void ConfigWindow::on_cbMassnahmen_currentIndexChanged ( int index) {
    2. QLocale loc;
    3.  
    4. currentMassnahme = mw->getMassnahmeFromRow(index);
    5. QString bez = currentMassnahme->getBezeichnung();
    6. ...
    To copy to clipboard, switch view to plain text mode 
    the two functions here are rather simple as well. mw is a pointer back to the MainWindow, with the function

    Qt Code:
    1. cMassnahme* MainWindow::getMassnahmeFromRow(int row) {
    2. return massnahmeFromID[row];
    3. }
    To copy to clipboard, switch view to plain text mode 
    and the second line refering to this function:

    Qt Code:
    1. QString cMassnahme::getBezeichnung() {
    2. return bezeichnung;
    3. }
    To copy to clipboard, switch view to plain text mode 

    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:n_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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Despair

    Quote Originally Posted by mikro View Post
    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?

  3. The following user says thank you to jacek for this useful post:

    mikro (8th October 2006)

  4. #3
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Despair

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.