Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Problems with QList...
Forum Updated to NodeBB v4.3 + New Features

[Solved] Problems with QList...

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 2.9k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    Well I'm having problems with this code:

    @
    Funcoes* funcoes = new Funcoes();
    TipoEixoDAO* tipoEixoDAO = new TipoEixoDAO();
    int aux = 0;
    for (int i=0; i < getQuantidadeSensores(); i++)
    {
    aux = i+1;
    Sensor* sensorVeiculo = new Sensor();
    sensorVeiculo->setNumero( aux );
    aux = funcoes->charToInt(getDados().at(enderecoMS));
    sensorVeiculo->setEndereco( funcoes->intToHexStr(aux) );

            aux = funcoes->charToInt(getDados().at(tipoMS)) ;
            TipoEixo* myTipoEixo = tipoEixoDAO->consultarPorTipo( funcoes->intToHexStr(aux) );
            Eixo* eixoVeiculo = new Eixo();
            eixoVeiculo->setConjunto( funcoes->charToInt(getDados().at(conjuntoMS)) );
            eixoVeiculo->setNumeroEixo( funcoes->charToInt(getDados().at(posicaoMS)) );
            eixoVeiculo->setMyTipoEixo( myTipoEixo );
            eixoVeiculo->setSensor( sensorVeiculo );
    
            this->veiculo->getListaEixo().append( eixoVeiculo );
            qDebug() << "Adicionou!!!!!!";
    

    // this->listaSensores.append( sensor );
    enderecoMS += quantidadeBytes;
    posicaoMS += quantidadeBytes;
    conjuntoMS += quantidadeBytes;
    tipoMS += quantidadeBytes;
    }
    delete funcoes;
    delete tipoEixoDAO;
    } else {
    CaixaDialogo::getMensagemErro("Erro ao Carregar informações dos sensores, nenhum sensor encontrado.")->exec();
    }
    qDebug() << "Quantidade de Sensores: " << this->veiculo->getListaEixo().size();
    @

    The output logger show the "Adicionou!!!!!!" 3 times... so the command "qDebug() << "Quantidade de Sensores: " << this->veiculo->getListaEixo().size();" need to show the size of 3 but is showing "0" still...
    What's can be?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on last edited by
      #2

      I solved this changing this:
      @
      this->veiculo->getListaEixo().append( eixoVeiculo );
      qDebug() << "Adicionou!!!!!!";
      @

      To this:
      @
      this->veiculo->addEixo(eixoVeiculo);
      qDebug() << "Adicionou!!!!!!";
      @

      I needed to implement the function addEixo()! Why this?!?!

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hostel
        wrote on last edited by
        #3

        What type is
        @
        veiculo
        @
        ?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

          A Class, is vehicle in portuguese.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hostel
            wrote on last edited by
            #5

            Ok but it is a QList<int> or QList< QString> or what?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              QList<MyClass*>

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hostel
                wrote on last edited by
                #7

                QList hasn't got a getListaEixo() so I think question is not about QList.

                1 Reply Last reply
                0
                • _ Offline
                  _ Offline
                  _rmn
                  wrote on last edited by
                  #8

                  what return type of
                  @
                  this->veiculo->getListaEixo()
                  @

                  It seems like it is QList<Eixo *>, right?
                  So you create QList object on stack and when it goes out of scope (on every iteration of for-loop) it is destroyed.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    The version you posted originally returns a copy of the list, appends an element there and then destroys that copy. The original list is never changed.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dcbasso
                      wrote on last edited by
                      #10

                      @
                      QList<Reboque*> listaReboque;

                      QList<Reboque*> Veiculo::getListaReboque()
                      {
                      return this->listaReboque;
                      }
                      @

                      I need to declare Like this:

                      @
                      QList<Reboque*> listaReboque*;
                      @

                      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