[Solved] Problems with QList...
-
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? -
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?!?!
-
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.