Results 1 to 3 of 3

Thread: QTableView crashes after doubleclick

  1. #1
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView crashes after doubleclick

    I have QTableView with QAbctractTableModel. One column can edit.

    When I doubleclick on it, editor is shown. I try to doubleclick another cell of this collumn and my application crashes.

    This is my code for editing:
    Qt Code:
    1. QVariant TxTableModelOrder::data(const QModelIndex &index, int role) const
    2. {
    3. if (role == Qt::DisplayRole) {
    4. return m_Data.getCellValue(index.row(), index.column());
    5. }
    6. if (role == Qt::EditRole) {
    7. return m_Data.getCellValue(index.row(), index.column());
    8. }
    9. if (role == Qt::BackgroundColorRole) {
    10. TxOrder order;
    11. return order.getStatusColor(m_Data.getCellValue(index.row(), QString("order_status")).toInt());
    12. }
    13. return QVariant();
    14. }
    15.  
    16. Qt::ItemFlags TxTableModelOrder::flags(const QModelIndex &index) const
    17. {
    18. Qt::ItemFlags flags = QAbstractTableModel::flags(index);
    19. QString columnName = m_Data.getColumnName(index.column());
    20.  
    21. if (columnName == "driver_callsign") {
    22. flags |= Qt::ItemIsEditable;
    23. }
    24.  
    25. return flags;
    26. }
    27.  
    28. bool TxTableModelOrder::setData(const QModelIndex &index, const QVariant &value, int role)
    29. {
    30. if (role == Qt::EditRole) {
    31. QString columnName = m_Data.getColumnName(index.column());
    32.  
    33. if (columnName == "driver_callsign") {
    34. QString primaryKey = m_Data.getRowFieldValue(index.row(), m_Data.getKeyField());
    35. QString callsign = value.toString();
    36. TxOrder order;
    37.  
    38. try {
    39. if (callsign.isEmpty()) {
    40. order.clearDriverOnOrder(primaryKey);
    41. } else {
    42. order.setDriverToOrderByCallsign(primaryKey, callsign);
    43. }
    44. } catch (TxException ex) {
    45. qDebug() << ex.getMessage();
    46. }
    47. }
    48. }
    49. return true;
    50. }
    To copy to clipboard, switch view to plain text mode 

    I can not find what is going wrong! Help please.


    Added after 15 minutes:


    Error message is:

    QObject::installEventFilter(): Cannot filter events for objects in a different thread.
    Last edited by nickla; 18th March 2011 at 16:30.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTableView crashes after doubleclick

    Do you use QThreads?

  3. #3
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView crashes after doubleclick

    No! I use QTimer for data download.

    Qt Code:
    1. TxTableModelOrder::TxTableModelOrder(QTableView *parent) :
    2. {
    3. this->parent = parent;
    4. timer = new QTimer(this);
    5.  
    6. connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
    7. connect(timer, SIGNAL(timeout()), this, SLOT(timerDone()));
    8. timer->start(1000);
    9. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 8 minutes:


    I have fixed this problem. I want somebody who will get this error to know what is wrong.

    Look at this code line 13 and 15:
    Qt Code:
    1. bool TxTableModelOrder::setData(const QModelIndex &index, const QVariant &value, int role)
    2. {
    3. if (role == Qt::EditRole) {
    4. QString columnName = m_Data.getColumnName(index.column());
    5.  
    6. if (columnName == "driver_callsign") {
    7. QString primaryKey = m_Data.getRowFieldValue(index.row(), m_Data.getKeyField());
    8. QString callsign = value.toString();
    9. TxOrder order;
    10.  
    11. try {
    12. if (callsign.isEmpty()) {
    13. order.clearDriverOnOrder(primaryKey);
    14. } else {
    15. order.setDriverToOrderByCallsign(primaryKey, callsign);
    16. }
    17. } catch (TxException ex) {
    18. qDebug() << ex.getMessage();
    19. }
    20. timer->start(1000);
    21. }
    22. }
    23. return true;
    24. }
    To copy to clipboard, switch view to plain text mode 

    There are http sync requests to server on these lines. That means we wait till server sends response, but QTableView can not wait when user decided to doubleclick in other cell and app crash.

    Use async request in setData - this is fix for my problem.
    Last edited by nickla; 18th March 2011 at 19:22.

Similar Threads

  1. doubleclick with tableview reacts only once
    By qt_gotcha in forum Newbie
    Replies: 1
    Last Post: 13th July 2010, 17:17
  2. QTimeEdit / QDateEdit doubleclick behavior
    By osiris81 in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 17:28
  3. Replies: 0
    Last Post: 20th May 2009, 10:01
  4. Prevent docking on doubleclick
    By yartov in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2008, 20:46
  5. [QT4 & XP] doubleClick on QtreeView
    By incapacitant in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 12:15

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.