QTableWidget Column Hold More Than One Item
Solved
General and Desktop
-
I want to get a cell of QTableWidget to hold more than one country name, separated with commas.
QByteArray answer = reply->readAll();
QJsonDocument doc = QJsonDocument::fromJson(answer);if(doc.isObject())
{
QJsonObject root = doc.object();
QJsonArray countriesArray = root["countries"].toArray();for(auto it = root.begin(); it != root.end(); ++it) { for(const QJsonValue &val : countriesArray) { if(it.key() == "countries") { QJsonObject obj = val QString countriesName = obj["name"].toString() + ", "; mpTable->setItem(mRow, 12, new QTableWidgetItem(countriesName)); } } }
}
-
Why don't you just append to
countryName
the values from the iso2 and iso3 elements? You could also create a QStringList with all of the versions of a country name and then use the result ofQStringList::join(",")
as the value for the table cell.