I want to be able to print a QList to a TextBox with setText(“ “), but I need to convert that list to a string. This may be trivial, but I’m new to cpp and Qt. essentially I want to do the following:
{1,2,3,4} -> “{1,2,3,4}”
I want to be able to print a QList to a TextBox with setText(“ “), but I need to convert that list to a string. This may be trivial, but I’m new to cpp and Qt. essentially I want to do the following:
{1,2,3,4} -> “{1,2,3,4}”
HiFile.app - best file manager
On
Improving a bit on the answer by JarMan. This should be more performant and more Qt-ish.
// Assuming QList of integers
QString list2String(const QList<int> &list)
{
QStringList strings;
strings.reserve(list.size());
for (int i : list)
{
strings.append(QString::number(i));
}
return QStringLiteral("{%1}").arg(strings.join(','));
}
Copyright © 2021 Jogjafile Inc.
QList is just a container. It doesn't know anything about strings. So you'll need to iterate over the list and append each value into the string.