PDA

View Full Version : Using STL in Qt4 vs. Qt3



hvw59601
4th November 2007, 15:42
Hi,

This shows my ignorance, but in Qt3 I could do:


// Find the latest mtime...
for (vector<string>::const_iterator iss = new_partitions->begin(); iss != new_partitions->end(); ++iss) {
QString this_string = (*iss);

to which I get an error:


do_test_gpc.cpp:323: error: conversion from 'const std::basic_string<char, std::char_traits<char>, std::allocato
r<char> >' to non-scalar type 'QString' requested

Could someone point out what should be done instead?
Thanks!

jpn
4th November 2007, 16:01
In Qt 4 you have QString::fromStdString().

DeepDiver
4th November 2007, 16:03
In Qt4 implicit convertion from std::string to QString is no longer supported.
You need to make use of QString QString::fromStdString ( const std::string & str ) (http://doc.trolltech.com/4.3/qstring.html#fromStdString)

Instead of :


...
QString this_string = (*iss);
...

You need to write:


...
QString this_string = QString::fromStdString(*iss);
...

hvw59601
4th November 2007, 16:18
Thanks a lot!!