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. QModelIndex invalid when returning from a dialog
Forum Updated to NodeBB v4.3 + New Features

QModelIndex invalid when returning from a dialog

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.2k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fluca1978
    wrote on 21 Oct 2011, 06:40 last edited by
    #1

    Hi all,
    in my project I've got a table view and I want to edit some rows using a qdialog subclass. In the dialog I've placed a qdatawidgetmapper to map wigets, and the submit policy is manual.
    Now when the user clicks the save button on the dialog something like the following happens:

    @
    qDebug() << "Current model row index is " << widgetMapper->currentIndex();
    tableView->selectRow( widgetMapper->currentIndex() );
    qDebug() << "Selected row " << tableView->currentIndex().row();
    qDebug() << "Index is valid " << tableView->currentIndex().isValid();@

    where tableview is an instance of a QTableView, widgetmapper is an instance of the QDataWidgetMapper.
    Now the outputs presents the following:

    @Current model row index is 3
    Selected row -1
    Index is valid false @

    So I'm editing the row number 3 of the table model, I want to select again such row when the dialog hides but suddenly the model index becomes invalid. Of course the widget mapper and the table view share the same QSqlRelationTableModel instance.
    Can anybody give me an hint?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on 21 Oct 2011, 09:17 last edited by
      #2

      I think I get it: the problem seems to be that the qdatawidgetmapper::submit() method invalidates (?) the currentIndex or something alike.
      In fact the following piece of code works fine:

      @int modelIndex = widgetMapper->currentIndex();
      retVal = widgetMapper->submit();
      // emphasize the current record
      tableView->selectRow( modelIndex );@

      while the following is not working:

      @
      retVal = widgetMapper->submit();
      // emphasize the current record
      ableView->selectRow( widgetMapper->currentIndex() );
      @

      The difference is that in the working code the current index of the qdatawidgetmapper is hold before the actual submit, so I guess the submit produces something on the widget mapper or the model itself that prevents the selection of such index. It is still not clear to me what really happens, can anybody explain better where the problem is?

      1 Reply Last reply
      0

      1/2

      21 Oct 2011, 06:40

      • Login

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