Results 1 to 2 of 2

Thread: BeginRemoveRows crash on deployment

  1. #1
    Join Date
    Feb 2016
    Qt products

    Default BeginRemoveRows crash on deployment

    This is my first post on here. I have ran into an interesting issue that I haven't been able to figure out for a couple of weeks. After trying many different things and reading lots of posts, I am now hoping somebody on here has an idea.

    I have a crash that only occurs on the deployed version of the software on computers that do not have Qt installed. I have used the Depends program for figuring out which DLLs I needed and recently tried using windeployqt as an alternative. My program is able to launch fine and run normally. However, there is a particular sequence of events I do that causes a crash only on the deployed version.

    I have used a program called DebugView and was able to trace the exact line that the program crashes. It crashes on a BeginRemoveRows statement. The code looks like the following in this function:
    Qt Code:
    1. bool AMPModel::removeItems(int position, int rows, const QModelIndex &parent)
    2. {
    3. AMPModelItem *parentItem = getItem(parent);
    4. bool success = true;
    6. beginRemoveRows(parent, position, position + rows - 1);
    7. success = parentItem->removeChildren(position, rows);
    8. endRemoveRows();
    10. return success;
    11. }
    To copy to clipboard, switch view to plain text mode 

    I have outputted the variables, the moment before the crash and get the following:
    position = 5
    rows = 1
    I also outputted the number of children of the parentItem which is 6. The QModelIndex exists, and so does the parentItem after the getItem function.

    I get the same variable output while running in debug mode on my development computer. However, it does not crash nor does running the same compiled version on that computer crash.

    The overall picture of what I'm doing is that I have a model that contains my data and I'm switching between two ways of viewing this model (a tree view and a graphical view that I created). It seems to crash when I click within the tree view (just select any item), switch to the graphical view, and try to delete an item. If I do not select an item within my tree view, then I do not get the crash.

    If anybody has any suggestions on what to try, I would really appreciate it. If you need more clarification, I would be happy to provide it.


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 601 Times in 591 Posts
    Qt products
    Unix/X11 Windows Android

    Default Re: BeginRemoveRows crash on deployment

    I am guessing that the problem has nothing at all to do with the code you posted. If everything checks out valid in both debug and release modes, then it is probably OK.

    What I think is happening is that you have an uninitialized pointer or other variable that gets used or that another part of your program is corrupting memory and it causes a crash that is apparent only in release mode.

    When you compile and run in debug mode, your code gets instrumented with all sorts of things to help in the debugging process - variables and pointers get initialized to known, bogus values, stack trace code gets inserted, etc. Memory usage and layout are different. It isn't the same program as the one that gets built for release mode.

    So first rebuild your program with the highest warning level. Second, add checks to make sure that every pointer you use is valid before you call through it (you aren't doing that in the code you posted - you just assume "parentItem" is valid...). Third, check that calling arguments are valid before using them (like "position", and "rows"). Don't just do this via the debugger or print statements that you later remove. Those don't test your actual use conditions. Put in conditional statements to check it in the code and don't make the call if they aren't valid. In debug mode, you can use asserts for this, but that doesn't help in release mode.
    <=== 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. The following user says thank you to d_stranz for this useful post:

    Nekreg45 (13th September 2018)

Similar Threads

  1. QT 5.8 deployment crash on AMD drivers
    By mor619dx in forum Installation and Deployment
    Replies: 0
    Last Post: 7th February 2017, 14:10
  2. Replies: 6
    Last Post: 26th February 2016, 09:27
  3. beginInsertRows() beginRemoveRows()
    By RolandHughes in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2014, 23:07
  4. QModelIndex validity during beginRemoveRows
    By jkv in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2010, 12:02
  5. QAbstractItemModel::beginRemoveRows/endRemoveRows
    By SiS-Shadowman in forum Qt Programming
    Replies: 0
    Last Post: 12th July 2010, 09:56


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.