I have q method that shown at below:
void MainWindow::slotResults( const QList<QSqlRecord>& records )
{
ui->lineEditWord->setCompleter(0);
QStringList wordList;
for(int i = 0; i < records.count(); i++)
{
wordList.append( QString("%1").arg( records.value(i).value(0).toString()));
}
QCompleter *completer = new QCompleter(wordList, this);
// completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->lineEditWord->setCompleter(completer);
}
But, when line ui->lineEditWord->setCompleter(completer) have beeen execited; memory usage increase and when i call this method for several times, memory usage grow up. so how can i release memory from this? Should i remove current completer of lineEdit
pls help
The
QCompleterconstructor you are using takes aQStringListas parameter. It is certainly (while this is not documented properly), a convenience constructor that creates aQStringListModelfilled with the strings passed to the constructor and set this model as the completion model withQCompleter::setModel().You can update the string list represented by the model using the following code:
If you want to be sure of what you are doing, I suggest to create the completer and data model separately:
In this case, you just have to store the stringListModel as a member of your MainWindow and update the string list each time you pass through the
MainWindow::slotResults()method.