Hi folks...

I'm trying to get an app working using parameterized queries that I have working using a hand worked query successfully.

The code is below... description of what's not happening follows.

Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent)
  5. : QMainWindow(parent), ui(new Ui::MainWindowClass)
  6. {
  7. ui->setupUi(this);
  8. connect(ui->comboBox, SIGNAL(itemChanged(QModelIndex)), this, SLOT(showPriceData(QModelIndex)));
  9.  
  10. priceQueryModel = new QSqlQueryModel;
  11. query = new QSqlQuery;
  12. query->prepare("select p.shareid, p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareid"
  13. "where p.shareid = :share");
  14.  
  15. populateGroupBox();
  16. }
  17.  
  18. MainWindow::~MainWindow()
  19. {
  20. delete ui;
  21. }
  22.  
  23. void MainWindow::updatePriceData(int idx)
  24. {
  25. QSqlRecord record = comboQueryModel->record(idx);
  26. if(record.isEmpty())
  27. {
  28. qDebug() << "Error! Record is empty";
  29. return;
  30. }
  31. QVariant shareidx = record.value("shareid");
  32. query->bindValue(":share", shareidx.toInt());
  33. qDebug() << query->lastQuery();
  34.  
  35. priceQueryModel->setQuery(*query);
  36. if(priceQueryModel->lastError().isValid())
  37. qDebug() << priceQueryModel->lastError();
  38.  
  39. ui->tableView->setModel(priceQueryModel);
  40. priceQueryModel->removeColumn(0);
  41. priceQueryModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Closing Date"));
  42. priceQueryModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Share Price"));
  43. priceQueryModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Total Value"));
  44. priceQueryModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Company"));
  45. }
  46.  
  47. void MainWindow::populateGroupBox(void)
  48. {
  49. comboQueryModel = new QSqlQueryModel;
  50. comboQueryModel->setQuery("select sharename, shareid from shareid");
  51. ui->comboBox->setModel(comboQueryModel);
  52. }
To copy to clipboard, switch view to plain text mode 

The application output (from the query->lastQuery() call still has the variable as a variable, not as the bound value for some reason.

ie.
"select p.shareid, p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareidwhere p.shareid = :share"

Why is :share not the integer I've set it to?

Ta

Peter.