This isn't a 1-line solution. But is an extendable solution. What you basically do is create a template function to do the conversion for you in an exception-safe manner, like below:
namespace yournamespace {
template <typename U>
struct NumberToString {
QString operator()(const U& val) {
return QString::number(val);
}
};
template <typename T, typename U, typename Convertor>
void CopyArrayToVector(QVector<T>& dst, const U* src, const size_t size) {
QVector<T> temp;
temp.reserve(size);
for (int i = 0; i < size; ++i) {
temp.push_back(convert(src[i]));
}
dst.swap(temp);
}
}
Usage:
using yournamespace;
const size_t n = 10;
int *arr = new int[10];
QVector<String> dst;
CopyArrayToVector<QString,int,NumberToString<int> >(dst, arr, n);
DISCLAIMER: I'm not familiar with Qt framework. I whipped this up by looking at their documentation. Please feel free to correct me for any errors.