Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. Lista di oggetti
Qt 6.11 is out! See what's new in the release blog

Lista di oggetti

Scheduled Pinned Locked Moved Italian
2 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Ciao a tutti, ho provato a scrivere quest programma in modalità console, creo una QList e la riempio con oggetti.

    @

    #include <QCoreApplication>
    #include <iostream>
    #include "clspanino.h"
    #include "QTextStream"
    #include <QDebug>
    using namespace std;

    QTextStream t(stdin);
    static QList<clsPanino> Lista;
    void prendiValori(int i)// prendo il contatore solo per verifiche che adesso sono sotto commento
    {
    clsPanino oggetto;
    qDebug()<<"ciao, dammi un nome";
    oggetto.setValore(t.readLine());
    Lista.push_back(oggetto);
    /*
    qDebug()<<serieDiPanini[i].getValue();//stampo il nome dell'ultimo oggetto nel vettore
    if (i!=0) //stampo il nome dell'oggetto precedente
    qDebug()<<Lista[i-1].getValore();
    */

    }
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    for(int i=0;i<3;i++)
    prendiValori(i);
    foreach (clsPanino oggetto, Lista)
    {
    qDebug()<<oggetto.getValore();
    }
    return a.exec();
    }
    @
    Come output però mi da questo;

    ciao, dammi un nome
    pippo
    ciao, dammi un nome
    pluto
    ciao, dammi un nome
    paperino
    "paperino"
    "paperino"
    "paperino"

    Qualcuno sa spiegarmelo?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Ciao,

      prova in questo modo:

      @#include <QCoreApplication>
      #include <iostream>
      #include "clspanino.h"
      #include "QTextStream"
      #include <QDebug>
      using namespace std;

      QTextStream t(stdin);

      static QList<clsPanino> Lista;

      void prendiValori(int i)
      {
      clsPanino oggetto;

      qDebug() << "ciao, dammi un nome";
      
      oggetto.setValore(t.readLine());
      
      Lista.push_back(oggetto);   
      

      }

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      for(int i=0; i<3; i++) prendiValori(i);
      

      for (int j = 0; j < Lista.size(); j++ )
      {
      qDebug() << Lista.at(j).getValore();
      }
      return a.exec();
      }@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved