I had a problem with passing a template iterator of vector<'T>
to a function QString::fromStdString(const std::string&)
.
I had my function that in case of type T
can convert a std::string
to QString
or int
to QString
and than add in into my QTableWidget
cell.
The issue happen with converting from std::string
with:
error: no matching function for call to ‘QString::fromStdString(int&)’ QString text = QString::fromStdString(*it);
I can't understand why type of iterator object has int&
. What I do wrong? Can I convert it in other way?
template<typename T>
void Dialog::Browse(vector<T> *list, int &counter, QTableWidget *table, int column)
{
QTableWidgetItem* item = 0;
typename vector<T>::iterator it;
for (it = list->begin(); it != list->end(); ++it){
QString text;
if (typeid(*list) == typeid(vector<string>)){
//QString text = QString::fromUtf8(static_cast<string>(it)->c_str());
QString text = QString::fromStdString(*it);
} else if (typeid(*list) == typeid(vector<int>)){
QString text = QString::number(*it);
}
item = new QTableWidgetItem(text);
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
table->setItem(counter, column, item);
counter++;
}
}