Results 1 to 11 of 11

Thread: Weird application crash

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Weird application crash

    Hi to all!

    I need help because I stumbled into pitfall I cannot solve. In my app module I have QTableView subclassed object which represents data from subclassed QStandardItemModel object. This QStandardItemModel subclassed object internally holds QList of some data. Now, when I empty this QList with clear() method and after I clear QTableView also using its inherited clear method with following code chunk:
    Qt Code:
    1. m_pShoppingCartView->order()->orders()->clear(); // reinits order list
    2. m_pShoppingCartView->shoppingCartModel()->clear(); // clears table view
    To copy to clipboard, switch view to plain text mode 
    my app crashes with gdb error:
    Qt Code:
    1. warning: ASSERT: "i >= 0 && i < size()" in file ../../include/QtCore/../../src/corelib/tools/qbitarray.h, line 121
    To copy to clipboard, switch view to plain text mode 
    . The application crashes when I readd items to qlist and then render data of this qlist using model on table view. Why the app crashes?!
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird application crash

    Sometimes I also get:
    Qt Code:
    1. warning: ASSERT: "i >= 0 && i < size()" in file ../../include/QtCore/../../src/corelib/tools/qbitarray.h, line 121
    2.  
    3. warning: QPaintEngine::setSystemClip: Should not be changed while engine is active
    4.  
    5. warning: QPaintEngine::setSystemClip: Should not be changed while engine is active
    6.  
    7. warning: QWidgetPrivate::beginSharedPainter: Painter is already active
    8.  
    9. warning: QPainter::begin: A paint device can only be painted by one painter at a time.
    10.  
    11. warning: QPainter::begin: A paint device can only be painted by one painter at a time.
    12.  
    13. warning: ASSERT: "sharedPainter ? sharedPainter->isActive() : true" in file kernel\qwidget.cpp, line 4420
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    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: Weird application crash

    How is the order list related to the model? Do you emit proper signals when changing the model?

  4. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird application crash

    Well, here is model header:
    Qt Code:
    1. #ifndef CSHOPPINGCARTMODEL_H_
    2. #define CSHOPPINGCARTMODEL_H_
    3.  
    4. // qt includes
    5. //#include <QAbstractTableModel>
    6. #include <QStandardItemModel>
    7. #include <QModelIndex>
    8. #include <QString>
    9.  
    10. #include "CMerchandizeOrder.h"
    11.  
    12. //class CShoppingCartModel : public QAbstractTableModel
    13. class CShoppingCartModel : public QStandardItemModel
    14. {
    15. public:
    16. CShoppingCartModel(CMerchandizeOrder* pMerchandizeOrder,
    17. QObject* pParent=0);
    18. int rowCount(const QModelIndex &parent = QModelIndex()) const;
    19. int columnCount (const QModelIndex & parent=QModelIndex()) const;
    20. QVariant data(const QModelIndex &index, int role) const;
    21. /*
    22.   bool setData(const QModelIndex &index,
    23.   const QVariant &value,
    24.   int role);
    25. */
    26.  
    27. inline CMerchandizeOrder* order()
    28. { return m_pMerchandizeOrder; };
    29. private:
    30. CMerchandizeOrder* m_pMerchandizeOrder;
    31. };
    32.  
    33. #endif /*CSHOPPINGCARTMODEL_H_*/
    To copy to clipboard, switch view to plain text mode 

    and its implementation:
    Qt Code:
    1. #include "CShoppingCartModel.h"
    2.  
    3. CShoppingCartModel::CShoppingCartModel(CMerchandizeOrder* pMerchandizeOrder,
    4. QObject* pParent)
    5. // : QAbstractTableModel(pParent), m_pMerchandizeOrder(pMerchandizeOrder)
    6. : QStandardItemModel(pParent), m_pMerchandizeOrder(pMerchandizeOrder)
    7. {
    8. setColumnCount(1); // sets column count
    9. setRowCount(pMerchandizeOrder->orders()->size()); // sets row count
    10. }
    11.  
    12. int CShoppingCartModel::rowCount(const QModelIndex& parent) const
    13. {
    14. return m_pMerchandizeOrder->orders()->size();
    15. }
    16.  
    17. int CShoppingCartModel::columnCount (const QModelIndex& parent) const
    18. {
    19. return 1;
    20. }
    21.  
    22. QVariant CShoppingCartModel::data(const QModelIndex &index, int role) const
    23. {
    24. if (!index.isValid())
    25. return QVariant();
    26. if(index.isValid() && role==Qt::DisplayRole)
    27. return m_pMerchandizeOrder->orders()->at(index.row()).strDisplayString;
    28. //QStandardItemModel::data(index, role);
    29. if(index.isValid() && role==Qt::FontRole)
    30. return QFont("Courier New",
    31. 18,
    32. QFont::Normal/*QFont::Bold*/);
    33. return QVariant(); // returns invalid record
    34. }
    35.  
    36. /*
    37. bool CShoppingCartModel::setData(const QModelIndex &index,
    38.   const QVariant &value,
    39.   int role)
    40. {
    41.   emit dataChanged(index, index);
    42.   return true;
    43. }
    44. */
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  5. #5
    Join Date
    May 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Weird application crash

    You could try to use a debugger (e.g. gdb on linux) to pinpoint the exact location where the application crashes. This usually also reveals error that causes the crash.

  6. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird application crash

    Quote Originally Posted by totycro View Post
    You could try to use a debugger (e.g. gdb on linux) to pinpoint the exact location where the application crashes. This usually also reveals error that causes the crash.

    Wll I did that, how could I otherwise show error strings ?!
    Qt 5.3 Opensource & Creator 3.1.2

  7. #7
    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: Weird application crash

    What is the point of having a QStandardItemModel if you reimplement all of its functionality to operate on a list? Either use QStringListModel with a simple reimplementation to return another font (although you can do that on the view level) or use QStandardItemModel properly. The extra list is completely redundant here.

  8. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird application crash

    wysota, will fix that, now it is mandatory to make the code work. Here is the code that uses model:
    Qt Code:
    1. // slot for choosing merchandize
    2. void COperationWIndow::chooseMerchandize()
    3. {
    4. structOrder tmpOrder; // temp order
    5. QList<QStandardItem*> OrderItemList; // order model item list
    6.  
    7. qDebug() << "m_iSelected: " << m_pMerchandizeBrowser->m_iSelected;
    8. // FIXED: m_pMerchandizeBrowser->m_iSelected does not correctly show the index of selected image
    9. /*
    10.   tmpOrder.iMerchandizeID=1;
    11.   tmpOrder.iMerchandizeQuantity=25;
    12.   tmpOrder.rMerchandizePrice=4.00;
    13.   tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice;
    14.   tmpOrder.strMerchandizeName=QString("Testni Artikel");
    15.   tmpOrder.strDisplayString=QString::number(tmpOrder.iMerchandizeID)+strMerchandizeSpaceDelimiter+\
    16.   QString(tmpOrder.strMerchandizeName)+strMerchandizeDelimiter+\
    17.   QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDelimiter+\
    18.   QString::number(tmpOrder.iMerchandizeQuantity)+strMerchandizeSpaceDelimiter+\
    19.   QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);
    20.   qDebug() << "tmpOrder.strDisplayString=" << tmpOrder.strDisplayString;
    21. */
    22.  
    23. // TODO: language id number must not be ignored in sql statement
    24. QString queryString("SELECT * from merchandize WHERE IdentificationNumber=%1 AND InUse=1;");
    25. int iMerchandizeId=m_pMerchandizeBrowser->m_iSelected+1; // calcualtes id
    26. queryString=queryString.arg(iMerchandizeId); // adds id to query string
    27. qDebug() << "Query: " << queryString; // debug
    28. QSqlQuery query(queryString); // sets up query from query string
    29. qDebug() << query.lastError().text(); // debug
    30. if (query.isActive())
    31. {
    32. while (query.next())
    33. {
    34. tmpOrder.iMerchandizeID=query.value(0).toInt();
    35. tmpOrder.iMerchandizeQuantity=1;
    36. tmpOrder.rMerchandizePrice=(qreal)query.value(3).toDouble();
    37. tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice;
    38. tmpOrder.strMerchandizeName=QString(query.value(2).toString());
    39. tmpOrder.strDisplayString=QString::number(tmpOrder.iMerchandizeID)+strMerchandizeSpaceDelimiter+\
    40. QString(tmpOrder.strMerchandizeName)+strMerchandizeDelimiter+\
    41. QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDelimiter+\
    42. QString::number(tmpOrder.iMerchandizeQuantity)+strMerchandizeSpaceDelimiter+\
    43. QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);
    44. }
    45.  
    46.  
    47. if(m_pShoppingCartView->order()->orders()->size()<=0)
    48. {
    49. // size of orders is zero, adds record to table
    50. m_pShoppingCartView->order()->orders()->append(tmpOrder); // adds order to internal qlist
    51. QStandardItem* pItem=new QStandardItem(QString(tmpOrder.strDisplayString));
    52. Q_CHECK_PTR(pItem); // checks creation
    53. m_pShoppingCartView->shoppingCartModel()->appendRow(pItem);
    54. }
    55. else
    56. {
    57. for(qint16 iIndex=0; iIndex<(qint16)m_pShoppingCartView->order()->orders()->size(); iIndex++)
    58. {
    59. qDebug() << " m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID (" \
    60. << m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID << ")==" \
    61. << "tmpOrder.iMerchandizeID (" << tmpOrder.iMerchandizeID << ")?";
    62. if(m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID==tmpOrder.iMerchandizeID)
    63. /*
    64.   qDebug() << " iMerchandizeId (" << iMerchandizeId \
    65.   << "tmpOrder.iMerchandizeID (" << tmpOrder.iMerchandizeID << ")?";
    66.   if(iMerchandizeId==tmpOrder.iMerchandizeID)
    67. */
    68. {
    69. // orderer merchandize found, so
    70. tmpOrder.iMerchandizeQuantity++; // update quantity
    71. tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice; // update total
    72. tmpOrder.strDisplayString=QString::number(tmpOrder.iMerchandizeID)+strMerchandizeSpaceDelimiter+\
    73. QString(tmpOrder.strMerchandizeName)+strMerchandizeDelimiter+\
    74. QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDelimiter+\
    75. QString::number(tmpOrder.iMerchandizeQuantity)+strMerchandizeSpaceDelimiter+\
    76. QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);
    77. m_pShoppingCartView->order()->orders()->replace((int)iIndex, tmpOrder); // saves changes
    78. m_pShoppingCartView->shoppingCartModel()->clear(); // clears table view
    79. for(qint16 iIndex=0; iIndex<(qint16)m_pShoppingCartView->order()->orders()->size(); iIndex++)
    80. {
    81. QStandardItem* pItem=new QStandardItem(QString(tmpOrder.strDisplayString)); // creates new item from order
    82. Q_CHECK_PTR(pItem); // checks creation
    83. OrderItemList.append(pItem); // adds item to list
    84. //m_pShoppingCartView->shoppingCartModel()->appendRow(pItem); // adds items
    85. }
    86. m_pShoppingCartView->shoppingCartModel()->appendRow(OrderItemList); // adds items
    87. break;
    88. }
    89. else
    90. {
    91. // ordered merchandize not found, so adds it
    92. m_pShoppingCartView->order()->orders()->append(tmpOrder); // adds order to internal qlist
    93. QStandardItem* pItem=new QStandardItem(QString(tmpOrder.strDisplayString)); // creates new item from list
    94. Q_CHECK_PTR(pItem); // checks creation
    95. m_pShoppingCartView->shoppingCartModel()->appendRow(pItem);
    96. break;
    97. } // for
    98. } // for
    99. } // if
    100. /*
    101.   m_pShoppingCartView->resizeColumnsToContents();
    102.   m_pShoppingCartView->resizeRowsToContents();
    103. */
    104. if(m_pOrderButton->isEnabled()==false)
    105. m_pOrderButton->setEnabled(true); // enables order buttn
    106. } // if
    107. }
    To copy to clipboard, switch view to plain text mode 
    The code
    Qt Code:
    1. /*
    2.   m_pShoppingCartView->resizeColumnsToContents();
    3.   m_pShoppingCartView->resizeRowsToContents();
    4. */
    To copy to clipboard, switch view to plain text mode 
    is commented because here the app crashes by resizeRows. Why?!
    Qt 5.3 Opensource & Creator 3.1.2

  9. #9
    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: Weird application crash

    You can't make an incorrect code work. Finding the real problem with a bad design will take more time than rewriting it using correct solutions. Either implement the model by subclassing from QAbstractListModel or switch to QStandardItemModel completely.

  10. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird application crash

    I've switched to QStandardItemModel, you saw it in the header file!!

    And the order list simply cannot be redundant because I need it in other parts of project. So I cannot have QStandardModel with this list or what now?!
    Qt 5.3 Opensource & Creator 3.1.2

  11. #11
    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: Weird application crash

    Quote Originally Posted by MarkoSan View Post
    I've switched to QStandardItemModel, you saw it in the header file!!
    No, you didn't. You subclassed the model (and did it incorrectly) and not used it.

    And the order list simply cannot be redundant because I need it in other parts of project. So I cannot have QStandardModel with this list or what now?!
    I don't know what can or can't be. I know all the functionality of your list is already in the standard item model. So either don't use the list or don't use QStandardItemModel. A proper approach is to get rid of QStandardItemModel, but it's more work to implement your own model instead of using the standard one.

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  3. Weird crash caused by a QTreeView
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2006, 18:31
  4. Gnome makes application crash
    By regix in forum Qt Programming
    Replies: 35
    Last Post: 18th August 2006, 19:44
  5. Replies: 5
    Last Post: 24th April 2006, 15:42

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.