Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Editable QSqlQueryModel closeEditor message
Forum Updated to NodeBB v4.3 + New Features

Editable QSqlQueryModel closeEditor message

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ZNohre
    wrote on last edited by
    #1

    Hey all,

    I'm getting "QAbstractItemView::closeEditor called with an editor that does not belong to this view" logged to the Application Output console when editing cells in Editable Query Model Example.

    I believe the issue is that the model is being reset before the delegate has had time properly cleanup based on the placement of "clear()" and "refresh()" within the setData method below.

    I've tried layering in the traditional model/view signals (beginResetModel, dataChanged, etc.) but must be missing something.

    The functionality is working fine, but want to have a better understanding of why this message is generating to fix in my application.

    bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, int /* role */)
    {
        if (index.column() < 1 || index.column() > 2)
            return false;
    
        QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0);
        int id = data(primaryKeyIndex).toInt();
    
        clear();
    
        bool ok;
        if (index.column() == 1) {
            ok = setFirstName(id, value.toString());
        } else {
            ok = setLastName(id, value.toString());
        }
        refresh();
        return ok;
    }
    
    M 1 Reply Last reply
    0
    • Z ZNohre

      Hey all,

      I'm getting "QAbstractItemView::closeEditor called with an editor that does not belong to this view" logged to the Application Output console when editing cells in Editable Query Model Example.

      I believe the issue is that the model is being reset before the delegate has had time properly cleanup based on the placement of "clear()" and "refresh()" within the setData method below.

      I've tried layering in the traditional model/view signals (beginResetModel, dataChanged, etc.) but must be missing something.

      The functionality is working fine, but want to have a better understanding of why this message is generating to fix in my application.

      bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, int /* role */)
      {
          if (index.column() < 1 || index.column() > 2)
              return false;
      
          QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0);
          int id = data(primaryKeyIndex).toInt();
      
          clear();
      
          bool ok;
          if (index.column() == 1) {
              ok = setFirstName(id, value.toString());
          } else {
              ok = setLastName(id, value.toString());
          }
          refresh();
          return ok;
      }
      
      M Offline
      M Offline
      mjsmithers
      wrote on last edited by
      #2

      @ZNohre I've had the same problem with my programs for years. They function just fine, but I'd like to better understand what's going on. Did you make any progress with this?

      JonBJ 1 Reply Last reply
      0
      • M mjsmithers

        @ZNohre I've had the same problem with my programs for years. They function just fine, but I'd like to better understand what's going on. Did you make any progress with this?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @mjsmithers
        Just in case, I'd change that sample code not to ignore role parameter. It should only do what it does if Qt::EditRole.

        Then I see it has 3 views. Does this occur on all of them?

        I agree: it seems to me clear()ing the model when your are editing an item in an attached view is not a good idea, if that is the cause of the message. Comment out the clear()?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          medyakovvit
          wrote on last edited by
          #4

          @ZNohre Such an error can appear when the same item delegate is used in multiple views.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved