How to scroll through a list and display the data by console in QT creator c ++

0

Good morning, I am creating the following method:

void MainWindow::agregarProyecto(QString nombre, QString descripcion, QString directorio)
{
    proyecto *unProyecto = new proyecto (nombre,descripcion,directorio);
    qDebug("Se va agregar el proyecto a la lista");
    listaProyectos.append(*unProyecto);
    QList<proyecto>::iterator i;
    for(i = listaProyectos.begin(); i!=listaProyectos.end(); i++){
        qDebug << (*i).getNombre();
    }
    delete unProyecto;
}

How can I go through the list using an iterator and display the data by console?

    
asked by marcos vasquez 15.05.2017 в 16:12
source

1 answer

1

To go through a list (a QList) the most convenient is the automatic iterator of the for command, if you do not have the compiler specification to C11, add it in your .pro.

 CONFIG  += c++11

Assuming that "Project" is a structure or an object and that "List" is a QList< Proyecto >

for (Proyecto ElProyecto : Lista )
   qDebug() << ElProyecto.Dato1 << ElProyecto.Dato2;
    
answered by 22.06.2017 в 17:35