PDA

View Full Version : removing old list and adding new list to qcompleter



QJak
5th May 2017, 23:07
hi i need to remove old qstringlist of qcompleter and add a new one. how can i di this.
for example i have this:


QStringList stringList;
stringList << "m0" << "m1" << "m2";
mCompleter = new QCompleter(stringlist, this);
mLineEdit->setCompleter(mCompleter);


now i want to remove stringlist and clear mCompleter and add stringlist2:


QStringList stringList2;
stringList2<< "m" << "mm" << "mmm";
//removing stringlist here!
//adding stringlist2 here!

d_stranz
5th May 2017, 23:46
QStringList stringList2;
stringList2<< "m" << "mm" << "mmm";

mCompleter->setModel( new QStringListModel( stringList2, mCompleter ) );


See QCompleter::setModel() to understand why mCompleter is used in the QStringListModel constructor.

QJak
6th May 2017, 14:00
QStringList stringList2;
stringList2<< "m" << "mm" << "mmm";

mCompleter->setModel( new QStringListModel( stringList2, mCompleter ) );


See QCompleter::setModel() to understand why mCompleter is used in the QStringListModel constructor.


thanks for replying but crashes while using
mCompleter->setModel( new QStringListModel( stringList2, mCompleter ) );

d_stranz
6th May 2017, 17:46
but crashes

And what does the debugger say about why the crash occurs? From your original code for creating the QCompleter in the first place and this code for changing the string list, it seems to follow what is described in the documentation. You don't show where you're actually using this code though, so that's why you need to look at what the debugger says.