babygal
8th October 2010, 10:53
How to write ByteArray into a text file?
I tried the code below but it is not working.
Code:
QString filename = "out.txt";
QModelIndex index = view->currentIndex();
QSqlRecord record = model->record(index.row());
int id = record.value(0).toInt();
QSqlQuery query;
query.exec("SELECT mesh_file FROM MESH_REPOSITORY WHERE scan_id = " + QString::number(id) );
if(query.next())
{
QByteArray meshbyte = query.value(0).toByteArray();
QFile file(filename );
if (file.open(QIODevice::WriteOnly))
{
file.write(meshbyte);
file.close();
}
}
I tried the code below but it is not working.
Code:
QString filename = "out.txt";
QModelIndex index = view->currentIndex();
QSqlRecord record = model->record(index.row());
int id = record.value(0).toInt();
QSqlQuery query;
query.exec("SELECT mesh_file FROM MESH_REPOSITORY WHERE scan_id = " + QString::number(id) );
if(query.next())
{
QByteArray meshbyte = query.value(0).toByteArray();
QFile file(filename );
if (file.open(QIODevice::WriteOnly))
{
file.write(meshbyte);
file.close();
}
}