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. primeInsert() and setValue not working QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

primeInsert() and setValue not working QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
qsqlrelationaltprimrinsertsetvalue
2 Posts 1 Posters 1.0k 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.
  • L Offline
    L Offline
    lukeQt
    wrote on 1 May 2015, 19:14 last edited by lukeQt 5 Jan 2015, 19:15
    #1

    Hi Everyone,

    I am using QSqlRelationalTableModel. I have subclass the model. I am using editStrategy onManualSubmit.
    This is the code I have so far. What is not working is the default values. I am using primeInsert so that dataChanged is not emitted each time insertRows is called. Why is setValue not working? Is this almost right?

    class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
        def __init__(self, database = None, table = None, parent = None):
            super(AppField, self).__init__(parent)
            self._table = table
            self._dbfname = database
            self.setupUi(self)
            # subclassed sqlrelationaltablemodel.
            self.model = AppModel(table = self._table, parent = self)
            self.app_field_tableView.setModel(self.model)
    
            self.add_row_pushButton.clicked.connect(self.add_row)
            self.model.primeInsert.connect(self.default_val)
            self.model.dataChanged.connect(self.submit)
    
        def submit(self, index):
            print "help"
            id = self.model.data(self.model.index(index.row(), ID))
            app_alias = self.model.data(self.model.index(index.row(), ALIAS))
            app_field = self.model.data(self.model.index(index.row(), APP_FIELD))
            app_def = self.model.data(self.model.index(index.row(), APP_DEF))
            if self.model.isDirty(self.model.index(index.row(), ALIAS)) or app_alias != "Event Alias Name":
                if self.model.isDirty(self.model.index(index.row(), APP_FIELD))  or app_field != "Event name":
                    if self.model.isDirty(self.model.index(index.row(), APP_DEF)) or app_def != "Event Definition":
                        self.model.submitAll()
                        if self.model.lastError().isValid():
                            if self.model.lastError().text() == "column app_field_alias is not unique Unable to fetch row":
                                self.model.revertAll()
                                ms = self.model.lastError().text()
    
    
        def default_val(self, rec):
            """
            add default values to the table. I can not use setData because that
            will emit dataChanged.
            This is not working.
            """
            query = QtSql.QSqlQuery()
            query.exec_("SELECT id from in_gtlf")
            if query.next():
                gtlf_id = query.value(0).toInt()[0]
                record = self.model.record(rec)
                record.setValue(1, "Event Alias Name")
                record.setValue(2, "Event name")
                record.setValue(3, "Event Definition")
                record.setValue(4, gtlf_id)
    
    
    
        def add_row(self):
            """
            This method adds rows to the model.
            """
            row = self.model.rowCount()
            if self.model.lastError().isValid():
                ms = self.model.lastError().text()
                QtGui.QMessageBox.warning(self,"warning", ms, QtGui.QMessageBox.Ok)
            else:
                self.model.insertRows(row, 1)
                self.model.submitAll()
                index = self.model.index(row, 1)
                if index.isValid():
                    self.app_field_tableView.edit(index)
            self.resizeRow()
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      lukeQt
      wrote on 4 May 2015, 03:18 last edited by
      #2

      Am I trying to do this incorrectly?

      1 Reply Last reply
      0

      1/2

      1 May 2015, 19:14

      • 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