Results 1 to 7 of 7

Thread: Crash with endResetModel

  1. #1
    Join Date
    May 2009
    Posts
    52
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Crash with endResetModel

    I have this code that crashes on endResetModel. I use static build and the crash only happens on some dude's machine, couldn't reproduce it on my 3 different machines whatever I tried. Is there something wrong with this code that I don't see? The data list is very small.

    Qt Code:
    1. beginResetModel();
    2.  
    3. getDataList().clear();
    4.  
    5. for (QVariantList record : recordList)
    6. {
    7. getDataList() << QPair<QString, int>(record.at(0).toString(), record.at(1).toInt());
    8. }
    9.  
    10. endResetModel();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,854
    Thanks
    271
    Thanked 788 Times in 778 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Crash with endResetModel

    Is there something wrong with this code that I don't see?
    Aside from the fact that you do absolutely no error checking to ensure that "record" is valid or that either of the values returned by "record.at()" are valid? No.

    getDataList() << QPair<QString, int>(record.at(0).toString(), record.at(1).toInt());
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2009
    Posts
    52
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash with endResetModel

    There's no need for that, I always get two values in there, and it ONLY crashes on a single machine with exactly the same data. I wonder if it's not some obscure bug in Qt that is triggered by some weird stuff on his Windows.

    I found a workaround that works everywhere, but I don't really like it:

    Qt Code:
    1. getDataList().clear();
    2.  
    3. for (QSqlRecord record : recordList)
    4. {
    5. getDataList() << QPair<QString, int>(record.value(0).toString(), record.value(1).toInt());
    6. }
    7.  
    8. QModelIndex topLeft = createIndex(0, 0);
    9. emit dataChanged(topLeft, topLeft);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,854
    Thanks
    271
    Thanked 788 Times in 778 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Crash with endResetModel

    There's no need for that, I always get two values in there
    Yeah, what's the point of checking for errors if you know your code will ALWAYS work. Except on some other dude's machine, and then you can just blame it on Qt or some weird stuff on Windows.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    524
    Thanked 81 Times in 76 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Crash with endResetModel

    Quote Originally Posted by Carlsberg View Post
    I always get two values in there[/CODE]
    Except when you don't and you do not notice... Refusing to add a check is contrary to trying to resolve the problem.

  6. #6
    Join Date
    May 2009
    Posts
    52
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash with endResetModel

    It's not the data for sure, don't make me elaborate why I'm so sure, just be a believer.

    There's something else though, this model is used in multiple combo boxes and the crash happens on a combo box hat is being refilled when another combo box using the same model emits currentIndexChanged(), like this:

    Qt Code:
    1. void QueryPanel::onArticleChanged(int index)
    2. {
    3. QString articleName = articleComboBox->currentText();
    4.  
    5. if (articleName.isEmpty() && articleComboBox->count() > 0)
    6. {
    7. articleComboBox->setCurrentIndex(0);
    8. }
    9. else
    10. {
    11. versionComboBoxModel->refresh(articleName);
    12. }
    13.  
    14. versionComboBox->setCurrentIndex(0);
    15. }
    To copy to clipboard, switch view to plain text mode 

    So it crashes on

    Qt Code:
    1. versionComboBoxModel->refresh(articleName);
    To copy to clipboard, switch view to plain text mode 

    which goes through the initial code up until endResetModel.

    The weird thing is that I use beginResetModel and endResetModel in some table models much more complicated and I have no problem there...

    PS. If you want to know how I'm so sure about data, it's because

    1) I made sure it always get 2 values - "lol" some would say
    2) If 1) is not true, then it would crash everywhere on the same input data, unless SQLite or Qt are garbage, which they are not
    3) I've seen with my own eyes (literally) that the dude runs the same thing (run on my side, ok, pack, send over, unpack, run, crash) - it's not like I believe what people say
    4) I've added debug logs that show the list is fine and it stops right before endResetModel

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,854
    Thanks
    271
    Thanked 788 Times in 778 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Crash with endResetModel

    It's not the data for sure, don't make me elaborate why I'm so sure, just be a believer.
    OK, fine, I believe you. But what your most recent comments indicate is that there are bugs in your code around handling the data. Something is becoming corrupted that on your partner's machine results in a crash in that piece of code. Maybe his machine has a different configuration - more memory, less memory, different run time DLLs, something that causes the bug to appear where it does on his machine but not on yours.

    The fact that you can get it to work by causing Qt to take a different path through the code (dataChanged() vs. endModelReset()) is a big clue that something has gone wrong elsewhere that just happens to show up here.

    The fact that you have been able to determine that the problem occurs when one part of the UI is still attempting to process the invalid model is another big clue. Either that part of the UI isn't listening for the modelAboutToBeReset() signal or the signal is received -after- it has already emitted its currentIndexChanged() signal. I would examine slots that are connected to that signal to see what is happening there.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qwt liveplot crash
    By Myzhar in forum Qwt
    Replies: 1
    Last Post: 31st October 2019, 16:58
  2. Replies: 0
    Last Post: 3rd November 2015, 18:58
  3. qml crash
    By waiter in forum Qt Quick
    Replies: 0
    Last Post: 11th July 2013, 03:43
  4. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 04:59
  5. Emit endResetModel using a QTimer
    By stefanadelbert in forum Qt Programming
    Replies: 5
    Last Post: 9th June 2010, 09:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.