Hello,

I have got two problems and I don't know how to repair to run correctly.

First problem:

Firstly I give some code.
Qt Code:
  1. #include <QtGui>
  2. #include <QtSql>
  3.  
  4. #include "listresourcesdialog.h"
  5. #include "ui_listresourcesdialog.h"
  6.  
  7. void listResourcesDialog::initializeModel(QSqlQueryModel *model)
  8. {
  9. model->setQuery("SELECT * FROM resources");
  10. model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
  11. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
  12. }
  13.  
  14.  
  15. listResourcesDialog::listResourcesDialog(QWidget *parent) : QWidget(parent), ui(new Ui::listResourcesDialog)
  16. {
  17. ui->setupUi(this);
  18. initializeModel(&model);
  19. ui->tableView->setModel(&model);
  20. }
  21.  
  22. listResourcesDialog::~listResourcesDialog()
  23. {
  24. delete ui;
  25. }
  26.  
  27.  
  28. void listResourcesDialog::changeEvent(QEvent *e)
  29. {
  30. QWidget::changeEvent(e);
  31. switch (e->type()) {
  32. case QEvent::LanguageChange:
  33. ui->retranslateUi(this);
  34. break;
  35. default:
  36. break;
  37. }
  38. }
To copy to clipboard, switch view to plain text mode 

All is ok but when I called constructor of this class I saw table but there is nothing there. But if I give in:

Qt Code:
  1. listResourcesDialog::listResourcesDialog(QWidget *parent) : QWidget(parent), ui(new Ui::listResourcesDialog)
  2. {
  3. ui->setupUi(this);
  4. initializeModel(&model);
  5. ui->tableView->setModel(&model);
  6. QMessageBox::information(this, tr("blabla"), tr("blalbla"));
  7. }
To copy to clipboard, switch view to plain text mode 

So I saw table with data from database, but if I accept QMessageBox (I click "OK") then data from table disappear. I don't know what is wrong and what can I do to run correctly.

Second problem:

Qt Code:
  1. QSqlQuery query;
  2. query.prepare("SELECT * FROM profiles WHERE name = :name");
  3. query.bindValue(":name", ui->lineEdit_2->text());
To copy to clipboard, switch view to plain text mode 


All is ok, when this query has been executed I have in object results of this query, but I don't know how can I check how records are in objects (like numRows()) I have to know how many records are in this object.

Has somebody any solutions?