PDA

View Full Version : How to write ByteArray into a text file?



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();
}

}

wysota
8th October 2010, 10:58
Please define "not working".

gboelter
8th October 2010, 11:25
May be it don't work because you forgot 'query.first()' after the SELECT statement?

babygal
11th October 2010, 04:11
Please define "not working".
not working = no out.txt generated in the working folder.

saa7_go
11th October 2010, 04:19
Do query.exec(), query.next() and file.open() return true?