I am trying to create a autocompleting lineedit using values from my SQLITE database, the problem is that there is not autocomplete in the line edit, the code i am using is below
AutoComplete();
QCompleter *Account_completer = new QCompleter(AccountList);
QCompleter *Product_completer = new QCompleter(ProductList);
Account_completer->setCaseSensitivity(Qt::CaseInsensitive);
Product_completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->lineEdit_Invoice_Account->setCompleter(Account_completer);
ui->lineEdit_Invoice_Product->setCompleter(Product_completer);
my autocomplete procedure is below
QSqlQuery Account;
QSqlQuery Product;
switch(ui->comboBox_Invoice_Account_Search->currentIndex())
{
case 0:
Account.prepare("SELECT Customer_ID FROM Customer");
Account.exec();
break;
case 1:
Account.prepare("SELECT Company_Name FROM Customer");
break;
case 2:
Account.prepare("SELECT Company_Owner FROM Customer");
break;
case 3:
Account.prepare("SELECT Phone_Number FROM Customer");
break;
case 4:
Account.prepare("SELECT BULSTAT FROM Customer");
break;
}
switch(ui->comboBox_Invoice_Product_Search->currentIndex())
{
case 0:
Product.prepare("SELECT Product_CODE FROM Product");
break;
case 1:
Product.prepare("SELECT Product_Name FROM Product");
break;
}
Account.exec();
qDebug() << "SQL QUERY Account:" << Account.executedQuery();
qDebug() << "SQL ERROR Account:" << Account.lastError();
while(Account.next())
AccountList = Account.value(0).toStringList();
Product.exec();
qDebug() << "SQL QUERY Product:" << Product.executedQuery();
qDebug() << "SQL ERROR Product:" << Product.lastError();
while(Product.next())
ProductList = Product.value(0).toStringList();
for(int x = 0; x <= Account.size(); x++)
qDebug() << AccountList.at(x).toLocal8Bit().constData() << endl;
for(int y = 0; y <= Product.size(); y++)
qDebug() << ProductList.at(y).toLocal8Bit().constData() << endl;
}
Thank you
Aucun commentaire:
Enregistrer un commentaire