Why does the following code:
Qt Code:
  1. CBrowserWindow::CBrowserWindow(QWidget *parent, CDatabaseFoundation* pDatabase, QString sTableName, QString windowCaption)
  2. : QDialog(parent)
  3. {
  4. m_pModel=new QSqlRelationalTableModel(parent); // creates new model
  5. Q_CHECK_PTR(m_pModel); // checks for succesful creation
  6. m_pModel->setTable(sTableName); // sets table name
  7.  
  8. m_pColumnNames=new QStringList(); // creates new string list
  9. Q_CHECK_PTR(m_pColumnNames); // checks for succesful creation
  10.  
  11. // fetches record
  12. m_pTableRecord=new QSqlRecord(); // creates new record
  13. Q_CHECK_PTR(m_pTableRecord); // checks for susccesful creation
  14. m_pTableRecord=&pDatabase->m_Database.record(sTableName); // fetches column names
  15. QSqlRecord tempRec=pDatabase->m_Database.record(sTableName); // fetches column names
  16. m_pTableRecord=new QSqlRecord(tempRec); // read column names
  17. Q_CHECK_PTR(m_pTableRecord);
  18.  
  19. if (!m_pTableRecord->isEmpty()) {
  20. for (m_iIndex=0; m_iIndex<m_pTableRecord->count(); m_iIndex++) {
  21. m_pColumnNames->append(m_pTableRecord->fieldName(m_iIndex));
  22. }
  23. } // if
  24.  
  25. createBrowserContens(this, pDatabase, m_pColumnNames); // creates browser controls
  26.  
  27. setWindowTitle(windowCaption); // sets window title
  28.  
  29. /*
  30.   delete m_pModel; // deletes pModel;
  31.   delete m_pTableRecord; // deletes m_pTableRecord
  32.   // just to be sure
  33.   m_pModel=0;
  34.   m_pTableRecord=0;
  35. */
  36. }
To copy to clipboard, switch view to plain text mode 
Here is also createBrowserContens(..):
Qt Code:
  1. void CBrowserWindow::createBrowserContens(QWidget* pParent, CDatabaseFoundation* pDatabase, QStringList* pColumnNames) {
  2. m_pHorizLayout=new QHBoxLayout();
  3. Q_CHECK_PTR(m_pHorizLayout); // chechks creation of horiz layout
  4. m_pVertLayout=new QVBoxLayout();
  5. Q_CHECK_PTR(m_pVertLayout); // checks creation of vertical layout
  6.  
  7. m_pView=new QTableView(this);
  8. Q_CHECK_PTR(m_pView); // checks creation of view
  9.  
  10. for(m_iIndex=0; m_iIndex<pColumnNames->count(); m_iIndex++) {
  11. pDatabase->m_pModel->setHeaderData(m_iIndex, Qt::Horizontal, m_pColumnNames->at(m_iIndex)); // sets column names
  12. qDebug() << m_iIndex << ": " << m_pColumnNames->at(m_iIndex);
  13. //pView->showColumn(m_iIndex); // shows the selected column
  14. }
  15.  
  16. m_pView->setModel(pDatabase->m_pModel); // sets model
  17. m_pView->setItemDelegate(new QSqlRelationalDelegate(m_pView));
  18.  
  19. m_pButtonAdd=new QPushButton(QObject::trUtf8("Dodaj"));
  20. Q_CHECK_PTR(m_pButtonAdd); // checks creation of pushbutton
  21.  
  22. m_pButtonChange=new QPushButton(QObject::trUtf8("Spremeni"));
  23. Q_CHECK_PTR(m_pButtonChange); // checks creation of pushbutton
  24.  
  25. m_pButtonDelete=new QPushButton(QObject::trUtf8("Briši"));
  26. Q_CHECK_PTR(m_pButtonDelete); // checks creation of pushbutton
  27.  
  28. m_pButtonClose=new QPushButton(QObject::trUtf8("Zapri"));
  29. Q_CHECK_PTR(m_pButtonClose);
  30.  
  31. // leyout setup
  32. m_pHorizLayout->addWidget(m_pButtonAdd);
  33. m_pHorizLayout->addWidget(m_pButtonChange);
  34. m_pHorizLayout->addWidget(m_pButtonDelete);
  35. m_pHorizLayout->addWidget(m_pButtonClose);
  36.  
  37. m_pVertLayout->addWidget(m_pView);
  38.  
  39. m_pVertLayout->addLayout(m_pHorizLayout);
  40.  
  41. pParent->setLayout(m_pVertLayout);
  42.  
  43. // button connectors
  44. connect(m_pButtonClose, SIGNAL(clicked()), this, SLOT(close()));
  45. }
To copy to clipboard, switch view to plain text mode 
does NOT display data fields in window??