Results 1 to 8 of 8

Thread: QsqlQueryModel Subclass

  1. #1
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default QsqlQueryModel Subclass

    This question may have been answered somewhere else already, but I just can't seem to find the answer. I'm using the model to display a set of data from a sql database. I'm using the QSqlQueryModel to retrieve the data.

    In the QSqlQueryModel I need to add a column that is editable for the user. The data needs to be saved in the model and not committed to the database. This means that the setData function from QSqlQueryModel needs to be implemented and change the internal data. Is this possible? And is there an example?

    Any help is appreciated, thanks.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QsqlQueryModel Subclass

    The better way is make use of a custom proxy model, and not disturb the QSqlQueryModel. Moreover implementing QSqlQueryModel::setData() may not be practical as you don't know how the QSqlQueryModel stores the data internally.

    The proxy model will add the extra column.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    Delphi (13th May 2013)

  4. #3
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QsqlQueryModel Subclass

    Thanks for your replay,

    So one of the correct ways, would be to create a QAbstractProxyModel subclass with the QSqlQuery model as sourcemodel.

    which functions do i need to implement/reimplement? by for of them i have no idea.

    Any help is appreciated, thanks.

    Qt Code:
    1. class SqlProxyModelAddColumn : public QAbstractProxyModel
    2. {
    3. public:
    4. SqlProxyModelAddColumn() : QAbstractProxyModel(){
    5.  
    6. }
    7.  
    8. virtual ~SqlProxyModelAddColumn(){
    9.  
    10. }
    11.  
    12. virtual QModelIndex mapFromSource( const QModelIndex & sourceIndex) const{
    13.  
    14. // what to do here?
    15. }
    16. virtual QModelIndex mapToSource( const QModelIndex & proxyIndex) const{
    17.  
    18. // what to do here?
    19. }
    20.  
    21. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const{
    22.  
    23. // what to do here?
    24.  
    25. if (row < 0 || column < 0)
    26. return QModelIndex();
    27.  
    28. return createIndex(row, column);
    29. }
    30. virtual QModelIndex parent(const QModelIndex &child) const{
    31.  
    32. // what to do here?
    33. }
    34.  
    35. virtual Qt::ItemFlags flags ( const QModelIndex & index ) const{
    36.  
    37. if (index.column() == sourceModel()->columnCount()) // extra colum
    38. return Qt::ItemIsEditable | Qt::ItemIsSelectable;
    39. return sourceModel()->flags(index);
    40.  
    41. }
    42.  
    43. virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ){
    44.  
    45. if (role != Qt::EditRole)
    46. return false;
    47.  
    48. if (!index.isValid())
    49. return false;
    50.  
    51. if (index.column() == sourceModel()->columnCount()){ // extra column
    52.  
    53. for ( int i = 0; i < LastColumn.count();++i){
    54.  
    55. if (LastColumn[i].first == index.row()){
    56. LastColumn.removeAt(i);
    57. LastColumn.append(qMakePair(index.row(),value.toString()));
    58. return true;
    59. }
    60.  
    61. LastColumn.append(qMakePair(index.row(),value.toString()));
    62. return true;
    63. }
    64. }
    65.  
    66. return sourceModel()->setData(index, value, role);
    67. }
    68.  
    69. virtual QVariant data ( const QModelIndex & proxyIndex, int role = Qt::DisplayRole ) const{
    70.  
    71. if (role != Qt::DisplayRole)
    72. return false;
    73.  
    74. if (!proxyIndex.isValid())
    75. return false;
    76.  
    77. if (proxyIndex.column() == sourceModel()->columnCount()){ // extra column
    78.  
    79. for ( int i = 0; i < LastColumn.count();++i){
    80.  
    81. if (LastColumn[i].first == proxyIndex.row())
    82. return LastColumn[i].second;
    83. }
    84.  
    85. return QString();
    86. }
    87.  
    88. return sourceModel()->data(proxyIndex, role);
    89. }
    90.  
    91. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const{
    92.  
    93. return sourceModel->rowCount()+1;
    94. }
    95.  
    96. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const{
    97.  
    98. return sourceModel->columnCount()+1;
    99. }
    100.  
    101. private:
    102. QList<QPair<int,QString> > LastColumn;
    103.  
    104. };
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QsqlQueryModel Subclass

    Here is an example
    ProxyModel.jpg
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include <QApplication>
    4.  
    5. // Add one extra column at the beginning
    6. class ProxyModel : public QAbstractProxyModel
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit ProxyModel(QObject * parent = 0)
    11. {
    12. ;
    13. }
    14.  
    15. void setSourceModel(QAbstractItemModel *sourceModel)
    16. {
    17. if(this->sourceModel() != sourceModel)
    18. {
    19. if(this->sourceModel() != 0)
    20. {
    21. disconnect(this->sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
    22. this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)));
    23. disconnect(this->sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    24. this, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
    25. disconnect(this->sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
    26. this, SIGNAL(columnsAboutToBeInserted (const QModelIndex &, int, int)));
    27. disconnect(this->sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
    28. this, SIGNAL(columnsInserted(const QModelIndex &, int, int)));
    29. disconnect(this->sourceModel(), SIGNAL(modelAboutToBeReset()),
    30. this, SIGNAL(modelAboutToBeReset()));
    31. disconnect(this->sourceModel(), SIGNAL(modelReset()),
    32. this, SIGNAL(modelReset()));
    33. disconnect(this->sourceModel(), SIGNAL(layoutAboutToBeChanged()),
    34. this, SIGNAL(layoutAboutToBeChanged()));
    35. disconnect(this->sourceModel(), SIGNAL(layoutChanged()),
    36. this, SIGNAL(layoutChanged()));
    37. disconnect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
    38. this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)));
    39. }
    40.  
    41. QAbstractProxyModel::setSourceModel(sourceModel);
    42.  
    43. connect(this->sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
    44. this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)));
    45. connect(this->sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    46. this, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
    47. connect(this->sourceModel(), SIGNAL(columnsAboutToBeInserted (const QModelIndex &, int, int)),
    48. this, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)));
    49. connect(this->sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
    50. this, SIGNAL(columnsInserted(const QModelIndex &, int, int)));
    51. connect(this->sourceModel(), SIGNAL(modelAboutToBeReset()),
    52. this, SIGNAL(modelAboutToBeReset()));
    53. connect(this->sourceModel(), SIGNAL(modelReset()),
    54. this, SIGNAL(modelReset()));
    55. connect(this->sourceModel(), SIGNAL(modelReset()),
    56. this, SIGNAL(modelReset()));
    57. connect(this->sourceModel(), SIGNAL(layoutAboutToBeChanged()),
    58. this, SIGNAL(layoutAboutToBeChanged()));
    59. connect(this->sourceModel(), SIGNAL(layoutChanged()),
    60. this, SIGNAL(layoutChanged()));
    61. connect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
    62. this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)));
    63. }
    64. }
    65.  
    66. QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const
    67. {
    68. if(!parent.isValid())
    69. {
    70. if(column == 0)
    71. return createIndex(row, column, -1);
    72. else
    73. return createIndex(row, column, 0);
    74. }
    75. return QModelIndex();
    76. }
    77.  
    78. QModelIndex parent(const QModelIndex & /*child*/) const
    79. {
    80. return QModelIndex();
    81. }
    82.  
    83. int rowCount(const QModelIndex & parent = QModelIndex()) const
    84. {
    85. if(!parent.isValid())
    86. return sourceModel()->rowCount(parent);
    87. return 0;
    88. }
    89.  
    90. int columnCount(const QModelIndex & parent = QModelIndex()) const
    91. {
    92. if(!parent.isValid())
    93. return sourceModel()->columnCount(parent) + 1;
    94. return 0;
    95. }
    96.  
    97. QModelIndex mapToSource(const QModelIndex & proxyIndex) const
    98. {
    99. if(proxyIndex.column() <= 0)
    100. return QModelIndex();
    101.  
    102. return sourceModel()->index(proxyIndex.row(), proxyIndex.column() - 1);
    103. }
    104.  
    105. QModelIndex mapFromSource(const QModelIndex & sourceIndex) const
    106. {
    107. return index(sourceIndex.row(), sourceIndex.column() + 1);
    108. }
    109.  
    110. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
    111. {
    112. if(orientation == Qt::Horizontal)
    113. {
    114. if(section <= 0)
    115. return QString("Proxy Column");
    116. return sourceModel()->headerData(section - 1, orientation, role);
    117. }
    118. return sourceModel()->headerData(section, orientation, role);
    119. }
    120.  
    121. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    122. {
    123. if((index.column() <= 0) and (role == Qt::DisplayRole))
    124. return QString("Proxy Data - Row:%1").arg(index.row());
    125.  
    126. return sourceModel()->data(mapToSource(index), role);
    127. }
    128.  
    129. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
    130. {
    131. if((index.column() <= 0) and (role == Qt::EditRole))
    132. {
    133. // TODO: store data into ProxyModel
    134. return true;
    135. }
    136. return sourceModel()->setData(mapToSource(index), role);
    137. }
    138. };
    139.  
    140. int main(int argc, char *argv[])
    141. {
    142. QApplication app(argc, argv);
    143.  
    144. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    145. db.setDatabaseName("Qt.sqlite");
    146.  
    147.  
    148. ProxyModel proxy;
    149. proxy.setSourceModel(&model);
    150.  
    151. QTableView view;
    152. view.setWindowTitle("QSqlQueryModel View");
    153. view.setModel(&model);
    154. view.show();
    155.  
    156. QTableView proxyView;
    157. proxyView.setWindowTitle("ProxyModel View");
    158. proxyView.setModel(&proxy);
    159. proxyView.show();
    160.  
    161. if(db.open())
    162. model.setQuery("SELECT Country, Location FROM Locations");
    163.  
    164. view.resizeColumnsToContents();
    165. proxyView.resizeColumnsToContents();
    166.  
    167. return app.exec();
    168. }
    169.  
    170. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. The following user says thank you to Santosh Reddy for this useful post:

    Delphi (15th May 2013)

  7. #5
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QsqlQueryModel Subclass

    Thanks for your replay,

    I implemented data and setdata from your example. But the data in the proxy column is not editable.
    Even when i reimplemented flags the column stayed gray and did not call setdata.
    EDIT sloved graynes by returning Qt::ItemIsEnabled flag EDIT
    What I'm doing wrong?

    compiling the code with qt 5 i got an error on row 74.

    return createIndex(row, column, 0);
    call of overloaded 'createIndex(int&, int&, int)' is ambiguous
    so i used the default. createIndex(int&, int&)


    Qt Code:
    1. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    2. {
    3. if((index.column() <= 0) and (role == Qt::DisplayRole)){
    4.  
    5. //return QString("Proxy Data - Row:%1").arg(index.row());
    6.  
    7. for (int i = 0; i < LastColumn.count();++i){
    8.  
    9. if (LastColumn[i].first == index.row())
    10. return LastColumn[i].second;
    11. }
    12.  
    13. return QString("temp");
    14.  
    15. }
    16.  
    17. return sourceModel()->data(mapToSource(index), role);
    18. }
    19.  
    20. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
    21. {
    22. qDebug() << "setdata";
    23.  
    24. if((index.column() <= 0) and (role == Qt::EditRole))
    25. {
    26. // TODO: store data into ProxyModel
    27. for ( int i = 0; i < LastColumn.count();++i){
    28.  
    29. if (LastColumn[i].first == index.row()){
    30. LastColumn.removeAt(i);
    31. LastColumn.append(qMakePair(index.row(),value.toString()));
    32. return true;
    33. }
    34. }
    35.  
    36. LastColumn.append(qMakePair(index.row(),value.toString()));
    37. return true;
    38. }
    39. return sourceModel()->setData(mapToSource(index), role);
    40. }
    41.  
    42. Qt::ItemFlags flags ( const QModelIndex & index ) const{
    43.  
    44. if (index.column() <= 0){
    45.  
    46. return (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    47.  
    48. }
    49.  
    50. return QAbstractProxyModel::flags(index);
    51.  
    52. }
    53.  
    54. private:
    55. QList<QPair<int,QString> > LastColumn;
    To copy to clipboard, switch view to plain text mode 
    Last edited by Delphi; 15th May 2013 at 12:44.

  8. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Thumbs up Re: QsqlQueryModel Subclass

    Ok I have ported to Qt 5.0.2, and the new column is not editable but cannot be saved, hope you can figure that out.

    Basically the problem is with QAbstractProxyModel, which extensively uses mapToSource(), and mapFromSource()
    mapToSource(): All proxy indexes (except the first column) will have a unique source index. All the first column indexes will map to invalid index
    mapFromSource(): All source indexes will have a uniue proxy index. This is just fine, but the first column indexes in proxy model cannot be accesable from any source index. Other way of saying it will be that mapFromSource() function will never be able to return a proxy model index from the first column.

    As a work around for this I created the invalid dummy index to able to get to the first column index of proxy model

    Any why I hope you understand what I did, here is the working code
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include <QtWidgets>
    4. #include <QApplication>
    5.  
    6. // Add one extra column at the begining
    7. class ProxyModel : public QAbstractProxyModel
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit ProxyModel(QObject * parent = 0)
    12. {
    13. ;
    14. }
    15.  
    16. void setSourceModel(QAbstractItemModel *sourceModel)
    17. {
    18. if(this->sourceModel() != sourceModel)
    19. {
    20. if(this->sourceModel() != 0)
    21. {
    22. disconnect(this->sourceModel(), SIGNAL(modelAboutToBeReset()),
    23. this, SIGNAL(modelAboutToBeReset()));
    24. disconnect(this->sourceModel(), SIGNAL(modelReset()),
    25. this, SIGNAL(modelReset()));
    26. disconnect(this->sourceModel(), SIGNAL(layoutAboutToBeChanged()),
    27. this, SIGNAL(layoutAboutToBeChanged()));
    28. disconnect(this->sourceModel(), SIGNAL(layoutChanged()),
    29. this, SIGNAL(layoutChanged()));
    30. }
    31.  
    32. QAbstractProxyModel::setSourceModel(sourceModel);
    33.  
    34. connect(this->sourceModel(), SIGNAL(modelAboutToBeReset()),
    35. this, SIGNAL(modelAboutToBeReset()));
    36. connect(this->sourceModel(), SIGNAL(modelReset()),
    37. this, SIGNAL(modelReset()));
    38. connect(this->sourceModel(), SIGNAL(modelReset()),
    39. this, SIGNAL(modelReset()));
    40. connect(this->sourceModel(), SIGNAL(layoutAboutToBeChanged()),
    41. this, SIGNAL(layoutAboutToBeChanged()));
    42. connect(this->sourceModel(), SIGNAL(layoutChanged()),
    43. this, SIGNAL(layoutChanged()));
    44. }
    45. }
    46.  
    47. QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const
    48. {
    49. if(!parent.isValid())
    50. return createIndex(row, column);
    51. return QModelIndex();
    52. }
    53.  
    54. QModelIndex parent(const QModelIndex & /*child*/) const
    55. {
    56. return QModelIndex();
    57. }
    58.  
    59. int rowCount(const QModelIndex & parent = QModelIndex()) const
    60. {
    61. if(!parent.isValid())
    62. return sourceModel()->rowCount(QModelIndex());
    63. return 0;
    64. }
    65.  
    66. int columnCount(const QModelIndex & parent = QModelIndex()) const
    67. {
    68. if(!parent.isValid())
    69. return sourceModel()->columnCount() + 1;
    70. return 0;
    71. }
    72.  
    73. QModelIndex mapToSource(const QModelIndex & proxyIndex) const
    74. {
    75. if(!proxyIndex.isValid())
    76. return QModelIndex();
    77.  
    78. if(proxyIndex.column() == 0)
    79. return createIndex(proxyIndex.row(), -1, (quintptr)-1); //<<<<<<<<<<<<<<<<<<<<<< This is a workaround. Note is weird to create a index of proxy model and return as if it were an index of sourceModel(), it is not a common but will work (at-least in this case)
    80.  
    81. return sourceModel()->index(proxyIndex.row(), proxyIndex.column() - 1);
    82. }
    83.  
    84. QModelIndex mapFromSource(const QModelIndex & sourceIndex) const
    85. {
    86. if(!sourceIndex.isValid())
    87. {
    88. if((sourceIndex.row() > -1) and //<<<<<<<<<<<<<<<<<<<<<< This is a workaround.
    89. (sourceIndex.column() == -1) and
    90. (sourceIndex.internalId() == (quintptr)-1) )
    91. return index(sourceIndex.row(), 0);
    92. else
    93. return QModelIndex();
    94. }
    95.  
    96. return index(sourceIndex.row(), sourceIndex.column() + 1);
    97. }
    98.  
    99. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
    100. {
    101. if(orientation == Qt::Horizontal)
    102. {
    103. if(section == 0)
    104. return QString("Proxy Column");
    105. return sourceModel()->headerData(section - 1, orientation, role);
    106. }
    107. return sourceModel()->headerData(section, orientation, role);
    108. }
    109.  
    110. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    111. {
    112. if(index.column() == 0)
    113. {
    114. if((role == Qt::DisplayRole) or (role == Qt::EditRole))
    115. return QString("Proxy Data - Row:%1").arg(index.row());
    116. else
    117. return QVariant();
    118. }
    119.  
    120. return sourceModel()->data(mapToSource(index), role);
    121. }
    122.  
    123. bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)
    124. {
    125. if((index.column() == 0) and
    126. ((role == Qt::DisplayRole) or (role == Qt::EditRole)))
    127. {
    128. // TODO: store data into ProxyModel for only column 0
    129. (void)value;
    130. emit dataChanged(index, index);
    131. return true;
    132. }
    133.  
    134. return sourceModel()->setData(mapToSource(index), value, role);
    135. }
    136.  
    137. Qt::ItemFlags flags(const QModelIndex & index) const
    138. {
    139. if(index.column() == 0)
    140. {
    141. Qt::ItemFlags flag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
    142. return flag;
    143. }
    144.  
    145. return sourceModel()->flags(mapToSource(index));
    146. }
    147. };
    148.  
    149. #define USE_QSTANDARDMODEL
    150.  
    151. int main(int argc, char *argv[])
    152. {
    153. QApplication app(argc, argv);
    154.  
    155. #ifdef USE_QSTANDARDMODEL
    156. model.setRowCount(5);
    157. model.setColumnCount(2);
    158. #else // USE_QSTANDARDMODEL
    159. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    160. db.setDatabaseName("Qt.sqlite");
    161.  
    162. #endif // USE_QSTANDARDMODEL
    163.  
    164. ProxyModel proxy;
    165. proxy.setSourceModel(&model);
    166.  
    167. QTableView view;
    168. view.setWindowTitle("QSqlQueryModel View");
    169. view.setModel(&model);
    170. view.show();
    171.  
    172. QTableView proxyView;
    173. proxyView.setWindowTitle("ProxyModel View");
    174. proxyView.setModel(&proxy);
    175. proxyView.show();
    176. proxyView.setEditTriggers(QTableView::DoubleClicked);
    177. proxyView.setItemDelegate(new QStyledItemDelegate(&proxyView));
    178.  
    179. #ifndef USE_QSTANDARDMODEL
    180. if(db.open())
    181. model.setQuery("SELECT Country, Location FROM Locations");
    182. #endif // USE_QSTANDARDMODEL
    183.  
    184. view.resizeColumnsToContents();
    185. proxyView.resizeColumnsToContents();
    186.  
    187. return app.exec();
    188. }
    189. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. The following user says thank you to Santosh Reddy for this useful post:

    Delphi (15th May 2013)

  10. #7
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QsqlQueryModel Subclass

    Thanks again,

    it is now clear for me, i thought that mapFromSource was not called by setting data.

    There is only 1 thing i do not understand, modelReset() is connected twice( r 37/39), so this is just a copy-past mistake or is it useful?

  11. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QsqlQueryModel Subclass

    There is only 1 thing i do not understand, modelReset() is connected twice( r 37/39), so this is just a copy-past mistake or is it useful?
    Yes it is copy paste leftovers, just ignore that. Moreove all the signal/slot connections in there are not required, just use the ones required for your functionality, also note that you may need to add more connections if required.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  12. The following user says thank you to Santosh Reddy for this useful post:

    Delphi (15th May 2013)

Similar Threads

  1. Replies: 2
    Last Post: 15th April 2013, 06:33
  2. QSqlQueryModel
    By StefanLatsch in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2010, 11:09
  3. Does 'QSqlQueryModel' have a bug?
    By nuntawat in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2010, 17:45
  4. Replies: 8
    Last Post: 12th February 2010, 02:41
  5. QSqlQueryModel write subclass
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.