convert each element of QVector<double> to QString and save in a text file
Hi,
there is a QVector<double> in name of "v1". Size of "v1" is 1000. I need to convert all this 1000 elements to QString (or convert to a QStringList) and then save this list into a text file. Please help me in this way.
thanks
Re: convert each element of QVector<double> to QString and save in a text file
Re: convert each element of QVector<double> to QString and save in a text file
If you want to save directly into the file, see QTextStream.
Cheers,
_
Re: convert each element of QVector<double> to QString and save in a text file
Quote:
Originally Posted by
Lesiok
thanks Lesiok,
I used this:
Code:
for(int y=0; y<v1.size(); y++)
{
qDebug
()<<
QString("%1").
arg(v1.
at(y
));
}
how could i save this in a file (text type) in a one column?
Re: convert each element of QVector<double> to QString and save in a text file
See anda_skoa's post above.
Re: convert each element of QVector<double> to QString and save in a text file
Thanks all
I used this and works well:
Code:
for(int y=0; y<v1.size(); y++)
{
list<<
QString("%1").
arg(v1.
at(y
));
}
g1f.setFileName("test.txt");
{
qDebug()<<"can not open to write";
}
for ( QStringList::Iterator it
= list.
begin(); it
!= list.
end();
++it
) df << *it << "\n";
g1f.flush();
g1f.close();
is there an optimal way to convert QVector<double> to QStringList? can we do this by QVector::toList()?
Re: convert each element of QVector<double> to QString and save in a text file
The most optimal way is to not create the string list.
Cheers,
_