PDA

View Full Version : QList to file



alextavara
25th November 2009, 14:31
I want to write a QList to a file and I get this error:


c:/Qt/2009.04/qt/include/QtCore/../../src/corelib/io/qdatastream.h:252: error: no match for 'operator<<' in 's << (+l)->QList<T>::at [with T = Registro::alumData](i)'


In my registro.h I have this:


typedef struct curData{
QString Nombre;
QList <int> Notas;
int Promedio;
}cursoRegistro;

typedef struct alumData{
QString Nombre;
int Codigo;
QList <cursoRegistro> Cursos;
int Promedio;
}alumnoRegistro;

QList <alumnoRegistro> Alumnos;


My function to save the file (in registro.cpp) is:



void Registro::guardarArchivo()
{
QString nombreArchivo = QFileDialog::getSaveFileName(this);
if (nombreArchivo.isEmpty()) {
return;
}

QFile file(nombreArchivo);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("No se puede abrir archivo"), file.errorString());
return;
}

QDataStream out(&file);
out << Alumnos;
}


I'm a beginner.

Lykurg
25th November 2009, 14:34
I'm a beginner.

That's fine, but then please use the Newbie section of this board next time.

You have to provide a <<-operator for your struct. Search the forum for that, since it was asked some month ago.