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. QDataWidgetMapper / QSqlRelationalTableModel do not update the database
Forum Updated to NodeBB v4.3 + New Features

QDataWidgetMapper / QSqlRelationalTableModel do not update the database

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 894 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.
  • H Offline
    H Offline
    hidromatrix
    wrote on last edited by
    #1

    I'm trying to create a form where I want to display a QSqlRelationalTableModel from a SQLITE database (see part of the code below). I'm using a QTableView and some widgets (lineEdits and combos) using a QDataWidgetMapper.

    For displaying purposes the code is working flawlessly, but changes in the QTableView and widgets are not being passed through the database.

    I tried to use different options of the setEditStrategy property and the following happens:

    1. Using on QSqlTableModel::OnFieldChange - it forbids me from editing through the table view and changes from the widgets are not passed through the table view and database

    2. Using QSqlTableModel::OnRowChange - The table view lets me do editing only once (can be any cell) but after that I can edit any other cell. Changes in the widgets can be done, but are not passed through the tableview, nor the model (as moving the records forwards and back, the changes are forgotten).

    3. Using QSqlTableModel::OnManualSubmit - All the GUI works fine, values can be edited in both table view and widgets, values are preserved but the values are not passed through the database (checked using queries and open another instance (MDI) of the form. I called submitAll() from a pushButton but didnt work.

    I tried signals and slots with:

    connect(tableModelStations, SIGNAL(dataChanged(QModelIndex,QModelIndex)), tableModelStations,SLOT(submitAll()));

    without succes and I also played around with the dataWidgetMapperStation->setSubmitPolicy, but no luck in there either.

    Does anyone have any idea on what's happening? Any help is greatly appreciated!

    Regards,

    Eduardo

    @ tableModelStations = new QSqlRelationalTableModel(this);
    dataWidgetMapperStations = new QDataWidgetMapper(this);

        tableModelStations->setTable("t100000_Stations");
        tableModelStations->setRelation(3, QSqlRelation("t911000_StationTypes","StationType", "StationType"));
        tableModelStations->setRelation(11, QSqlRelation("v908000_ElevationParameters", "ParameterID", "ParameterName"));
        tableModelStations->setSort(0, Qt::AscendingOrder);
    
    //    tableModelStations->setEditStrategy(QSqlTableModel::OnManualSubmit);
        tableModelStations->setEditStrategy(QSqlTableModel::OnFieldChange);
    //    tableModelStations->setEditStrategy(QSqlTableModel::OnRowChange);
    
        tableModelStations->select();
    
    
        ui->tableView_Stations->setModel(tableModelStations);
        ui->tableView_Stations->setEditTriggers(QAbstractItemView::DoubleClicked);
    
    
        tableModelStationTypes = tableModelStations->relationModel(3);
        tableModelElevationTypes = tableModelStations->relationModel(11);
    
    
    
        ui->comboBox_StationType->setModel(tableModelStationTypes);
        ui->comboBox_StationType->setModelColumn(0);
    
        ui->comboBox_ElevationType->setModel(tableModelElevationTypes);
        ui->comboBox_ElevationType->setModelColumn(1);
    
        // Set the widget mapper
    
        dataWidgetMapperStations->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
        dataWidgetMapperStations->setModel(tableModelStations);
    
    
        dataWidgetMapperStations->addMapping(ui->lineEdit_StationID, 0);
        dataWidgetMapperStations->addMapping(ui->lineEdit_ProjectID, 1);
        dataWidgetMapperStations->addMapping(ui->lineEdit_LocalName, 2);
        dataWidgetMapperStations->addMapping(ui->comboBox_StationType, 3);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Easting, 4);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Northing, 5);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Latitude, 6);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Longitude, 7);
        dataWidgetMapperStations->addMapping(ui->lineEdit_LatLonDatum, 8);
        dataWidgetMapperStations->addMapping(ui->lineEdit_CoordinateSystem, 9);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Elevation, 10);
        dataWidgetMapperStations->addMapping(ui->comboBox_ElevationType,11);
        dataWidgetMapperStations->addMapping(ui->lineEdit_ElevationDatum, 12);
        dataWidgetMapperStations->addMapping(ui->lineEdit_SurveyMethod, 13);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Surveyor, 14);
        dataWidgetMapperStations->addMapping(ui->dateEdit_SurveyDate, 15);
        dataWidgetMapperStations->addMapping(ui->lineEdit_LandTenure, 16);
        dataWidgetMapperStations->addMapping(ui->lineEdit_Region, 17);
        dataWidgetMapperStations->addMapping(ui->lineEdit_MiningLease, 18);@
    

    @ dataWidgetMapperStations->addMapping(ui->plainTextEdit_Comments, 19);
    dataWidgetMapperStations->addMapping(ui->lineEdit_Source, 20);
    dataWidgetMapperStations->addMapping(ui->dateEdit_SourceDate, 21);
    dataWidgetMapperStations->addMapping(ui->lineEdit_EntryAuthor, 22);
    dataWidgetMapperStations->addMapping(ui->dateEdit_EntryDate, 23);

        dataWidgetMapperStations->toFirst();@
    
    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