[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?!?!
-
What type is
@
veiculo
@
? -
A Class, is vehicle in portuguese.
-
Ok but it is a QList<int> or QList< QString> or what?
-
QList<MyClass*>
-
QList hasn't got a getListaEixo() so I think question is not about QList.
-
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. -
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.
-
@
QList<Reboque*> listaReboque;QList<Reboque*> Veiculo::getListaReboque()
{
return this->listaReboque;
}
@I need to declare Like this:
@
QList<Reboque*> listaReboque*;
@