I have this class:
Qt Code:
  1. #include <QTableWidgetItem>
  2. #include <QSignalMapper>
  3. #include <QCompleter>
  4. #include <QSqlError>
  5. #include <QSqlTableModel>
  6.  
  7. #include "bill.h"
  8.  
  9. #include <QMessageBox>
  10.  
  11. PrintBill::PrintBill(QWidget *parent) : QDialog(parent),
  12. ui(new Ui::PrintBill)
  13. {
  14. ui->setupUi(this);
  15.  
  16. ui->billTableWidget->setSelectionBehavior (QAbstractItemView::SelectItems );
  17. ui->billTableWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
  18. ui->billTableWidget->setRowCount(1);
  19. ui->billTableWidget->setColumnCount (5);
  20. ui->billTableWidget->setHorizontalHeaderLabels (labels);
  21. ui->billTableWidget->setColumnWidth (0, 63);
  22. ui->billTableWidget->setColumnWidth (1, 400);
  23. ui->billTableWidget->setColumnWidth(2, 100);
  24. ui->billTableWidget->setColumnWidth(3, 63);
  25. ui->billTableWidget->setColumnWidth(4, 85);
  26.  
  27. QLineEdit *product = new QLineEdit;
  28. ui->billTableWidget->setCellWidget(0, 1, product);
  29. sigMapper = new QSignalMapper(this);
  30. connect(product, SIGNAL(textEdited(QString )), sigMapper, SLOT(map()));
  31. sigMapper->setMapping(product, txt);
  32. connect(sigMapper, SIGNAL(mapped(QString )), this, SLOT(suggestItem()));
  33.  
  34. }
  35.  
  36. void PrintBill::printBill()
  37. {
  38. }
  39.  
  40. void PrintBill::suggestItem()
  41. {
  42. QLineEdit *product = static_cast<QLineEdit *>(ui->billTableWidget->cellWidget(0, 1));
  43.  
  44. /* sqlQuery = "SELECT Name FROM Items WHERE Name LIKE '%" + product->text() + "%'";
  45.   query.exec(sqlQuery);
  46.   rec = query.record();
  47.  
  48.   QMessageBox msg;
  49.   msg.setText(product->text() + QString::number(query.numRowsAffected()));
  50.   //msg.exec();
  51.   while(query.next())
  52.   {
  53.   items << query.value(rec.indexOf("Name")).toString();
  54.   msg.setText( query.value(rec.indexOf("Name")).toString());
  55.   msg.exec();
  56.   }
  57. */
  58. QCompleter suggestions(items);
  59. suggestions.setCaseSensitivity(Qt::CaseInsensitive);
  60. suggestions.setModel(model);
  61. suggestions.setCompletionColumn(1);
  62. suggestions.setCompletionMode(QCompleter::PopupCompletion);
  63. model->setTable("Items");
  64. model->select();
  65. model->setFilter("Name LIKE '%" + product->text() + "%'");
  66.  
  67. product->setCompleter(&suggestions);
  68. }
  69.  
  70. PrintBill::~PrintBill()
  71. {
  72. delete ui;
  73. }
To copy to clipboard, switch view to plain text mode 
Now, if I type any thing, no data appear in the QLineEdit, the connection is steal open. I tried also query.numRowsAffected() but always return -1.