hi
i write a QString array in a file in binary mode and then read it from the file. the code is below. for what is it read wrong? and is QString suitable for saving these names?
for(int i=0; i<125; i++)
{
names
[i
] = QString("Name%1").
arg(i
+1);
//is QString suitable for saving these names? }
namef1.setFileName("names.bin");
if(!namef1.
open(QFile::ReadOnly)) {
qDebug()<<"can not open to read";
}
namef1.
read((char*)names,
125*sizeof(QString));
namef1.close();
QString names[125];
for(int i=0; i<125; i++)
{
names[i] = QString("Name%1").arg(i+1);//is QString suitable for saving these names?
}
QFile namef1;
namef1.setFileName("names.bin");
if(!namef1.open(QFile::ReadOnly))
{
qDebug()<<"can not open to read";
}
namef1.read((char*)names, 125*sizeof(QString));
namef1.close();
To copy to clipboard, switch view to plain text mode
namef.setFileName("names.bin");
if(!namef.
open(QFile::WriteOnly)) {
qDebug()<<"can not open to write";
}
namef.
write((char*)names,
125*sizeof(QString));
namef.flush();
namef.close();
QFile namef;
namef.setFileName("names.bin");
if(!namef.open(QFile::WriteOnly))
{
qDebug()<<"can not open to write";
}
namef.write((char*)names, 125*sizeof(QString));
namef.flush();
namef.close();
To copy to clipboard, switch view to plain text mode
thanks for any help
Bookmarks