Results 1 to 2 of 2

Thread: QList to file

  1. #1
    Join Date
    Nov 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QList to file

    I want to write a QList to a file and I get this error:
    Qt Code:
    1. 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)'
    To copy to clipboard, switch view to plain text mode 

    In my registro.h I have this:
    Qt Code:
    1. typedef struct curData{
    2. QString Nombre;
    3. QList <int> Notas;
    4. int Promedio;
    5. }cursoRegistro;
    6.  
    7. typedef struct alumData{
    8. QString Nombre;
    9. int Codigo;
    10. QList <cursoRegistro> Cursos;
    11. int Promedio;
    12. }alumnoRegistro;
    13.  
    14. QList <alumnoRegistro> Alumnos;
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. void Registro::guardarArchivo()
    2. {
    3. QString nombreArchivo = QFileDialog::getSaveFileName(this);
    4. if (nombreArchivo.isEmpty()) {
    5. return;
    6. }
    7.  
    8. QFile file(nombreArchivo);
    9. if (!file.open(QIODevice::WriteOnly)) {
    10. QMessageBox::information(this, tr("No se puede abrir archivo"), file.errorString());
    11. return;
    12. }
    13.  
    14. QDataStream out(&file);
    15. out << Alumnos;
    16. }
    To copy to clipboard, switch view to plain text mode 

    I'm a beginner.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QList to file

    Quote Originally Posted by alextavara View Post
    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.

Similar Threads

  1. How to write a QList into a binary file?
    By Lawand in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2009, 10:04
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. QList problem
    By lvi in forum Qt Programming
    Replies: 3
    Last Post: 25th August 2008, 18:22
  4. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.