form.h
Qt Code:
  1. class form:public QDialog, Ui::form
  2. {
  3. Q_OBJECT
  4. public:
  5. bool isUpdate;
  6. QString totaID;
  7. form(QWidget *parent = 0
  8. , const QString &uid = QString::nulll);
  9. public slots:
  10. double calculate(const QString &id);
  11. };
  12.  
  13. #endif
To copy to clipboard, switch view to plain text mode 

form.cpp

Qt Code:
  1. double form::calculate(const QString &id)
  2. {
  3. totaID = id;
  4. load();
  5.  
  6. return spin->value();
  7. }
To copy to clipboard, switch view to plain text mode 

and after that I create a custom sqltablemodel

Qt Code:
  1. QVariant CustomSql::data(const QModelIndex &index, int role) const
  2. {
  3. QVariant value = QSqlTableModel::data(index, role);
  4. if (value.isValid() && role == Qt::DisplayRole) {
  5. if (index.column() == 5){
  6. calculate(index.sibling(index.row(),3).data().toString());
  7. return QString("%L1").arg((d),0,'f',2).leftJustified(true);
  8. }
  9. return value.toString().leftJustified(true);
  10. }
  11. return value;
  12. }
To copy to clipboard, switch view to plain text mode 


am I clear?