Reputation: 728
I am unable to use the function fromStdString. it is said in the qt assistant that, "This operator is only available if Qt is configured with STL compatibility enabled.". but i don know how to enable this. please provide the solution.
int main(int argc, char *argv[])
{
std::string read;
QString monthsArr[12];
QStringList monthlist;
std::ifstream readfile;
readfile.open("/home/pcamdin/practice/qtcpp/qtprogs/qtcpp/months.txt");
for(int i=0; i<6; i++)
{
readfile >> read;
monthsArr[i] = fromStdString(read);
monthlist << monthsArr[i];
qDebug() << i+1 << ": " << monthsArr[i];
}
qDebug() << "the first " << monthlist.size() << " months of the year are " << monthlist;
}
Upvotes: 1
Views: 2286
Reputation: 116
Even if Qt was configured with -no-stl you can interact with std::string and containers, it only disables some syntactictic sugar. You can e.g. used QString::fromLatin1(some_std_string.c_str(), some_std_string.size()) or QString::fromUtf8(...) or fromLocal8bit(...) depending on the encoding of the data in the std::string. This is arguably favorable in any case as it makes the encoding concersion explicit.
Upvotes: 2
Reputation: 7982
STL support is compiled in by default (at least when you build it yourself).
Unless something has changed in 4.8 that I am unaware of, fromStdString is a static member of QString, so you should be calling it like
monthsArr[i] = QString::fromStdString(read);
Simply calling fromStdString in the global namespace does not compile under 4.7.3.
Upvotes: 3