Results 1 to 8 of 8

Thread: QList crash in destructor

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QList crash in destructor

    When my function containing a QList<QTableWidgetSelectionRange> goes out of scope I get a crash in ~QList(). The call to this function is a response to a button click in a QDialog.

    My intent is to find all rows with at least one cell selected and store a string from a cell in that row.
    Qt Code:
    1. void Detect::on_Btn_clicked( void )
    2. {
    3. QList<QTableWidgetSelectionRange> list = ui.table->selectedRanges();
    4. QStringList sList;
    5.  
    6. for ( int i = 0; i < list.count(); i++ )
    7. {
    8. if ( !sList.contains( ui.table->item( list[i].topRow(), COL2_IP )->text() ) )
    9. sList.append( ui.table->item( list[i].topRow(), COL2_IP )->text() );
    10. }
    11.  
    12. accept();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Even stripping the function to just:
    Qt Code:
    1. void Detect::on_Btn_clicked( void )
    2. {
    3. QList<QTableWidgetSelectionRange> list = ui.table->selectedRanges();
    4. accept();
    5. }
    To copy to clipboard, switch view to plain text mode 
    still causes the crash.

    My debugger lists a stack trace of:
    Qt Code:
    1. msvcr71d.dll!operator delete(void* pUserData=non-zero)
    2. QTableWidgetSelectionRange::`scalar deleting destructor'()
    3. QList<QTableWidgetSelectionRange>::node_destructQList<QTableWidgetSelectionRange>::Node*from=non-zero)
    4. QList<QTableWidgetSelectionRange>::free(QListData::Data*data=non-zero)
    5. QList<QTableWidgetSelectionRange>::~QList<QTableWidgetSelectionRange>()
    6. Detect::on_Btn_clicked()
    To copy to clipboard, switch view to plain text mode 

    All data in the stack trace is non-zero so I don't think I've got a NULL pointer causing the problem. Is there some maintainence that must be done to the contents of the QList before the function ends?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QList crash in destructor

    Sounds interesting, but I can't reproduce this with Qt 4.2.0. Could you provide a minimal compilable example that reproduces the crash.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList crash in destructor

    I have hacked out everything I could to show how this is failing for me. A table with a single row and column is displayed. I select the cell and attempt to copy (Ctrl+C) which calls a function that has in it only:
    Qt Code:
    1. QList<QTableWidgetSelectionRange> list = m_pTable->selectedRanges();
    2. if ( list.count() > 1 )
    3. return;
    To copy to clipboard, switch view to plain text mode 
    The crash occurs when leaving the function. I am using Qt 4.1.0 with Microsoft Visual Studio 2003 (Visual C++.NET).

    If you cannot see a problem or reproduce the problem; I am just trying to determine which rows have a cell selected in them. Is there a better way to accomplish this than using QTableWidget::selectedRanges()?

    Thank you for looking at this problem.
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QList crash in destructor

    Try updating your Qt to a recent version. I couldn't get it to crash with Qt 4.1.4 nor Qt 4.2.0 / MSVC 2005.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    mclark (11th October 2006)

  6. #5
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList crash in destructor

    Interesting. I am having the same problem.

    This is what is causing mine to crash:
    Qt Code:
    1. bool CINAdminWindow::ViewStats()
    2. {
    3. QList<QTableWidgetSelectionRange> qlRange = ui.tblResults->selectedRanges();
    4.  
    5. if (qlRange.size() != 1)
    6. {
    7. //"Please Select One Spool"
    8. return false;
    9. }
    10.  
    11. int nRow = (*qlRange.begin()).topRow();
    12.  
    13. QString sSpoolID = ui.tblResults->item(nRow, 0)->text();
    14.  
    15. return true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    I have noticed that when it returns true (even when I comment out the "int nRow" and "QString sSpoolID" lines) it crashes but does not when it returns false.

    It is very odd. I am using MS VS 2003 /w Qt 4.2.0.

    They are on 4.2.2... maybe I should upgrade?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QList crash in destructor

    Maybe you should check if by any chance item() returns null.

  8. #7
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList crash in destructor

    I would beleive that if it where not for the fact that when I comment out those lines it fails if it returns true.

  9. #8
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList crash in destructor

    Since jpn cannot reproduce this while using 4.1.4 or Qt 4.2.0 / MSVC 2005, I'm beginning to think this could be a problem with the MSVC 2003 C++ compiler in the way it's handling the QList<QTableWidgetSelectionRange> destructor. No proof, but the only commonality between bpetty's and my crashes is the MS compiler as I'm using Qt 4.1. This wouldn't be the first (nor the second) time I've been bitten by a MS compiler bug!

    In the meantime I've switched to a more inefficient implementation but have kept the problematic code around. When this project is completed (within 6 weeks) I'll switch to Qt 4.2.x and retest the code. If it still breaks I'll lobby for a switch to MSVC 2005 and try again. It's kind of masochistic, but I need to know what the problem is.

Similar Threads

  1. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  2. Qt/Embedded Installation error during make
    By mahe2310 in forum Installation and Deployment
    Replies: 5
    Last Post: 7th September 2006, 04:05
  3. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20
  4. QMap destructor bug
    By Ruud in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2006, 09:08
  5. use libs under qt4
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 27th February 2006, 17:59

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.