tranfuga25s
30th July 2007, 14:51
Using qt4 with a QSqlRelationalTableModel, if I try to use one method of the relational model with:
MProductos *m = qobject_cast<MProductos *>(this->relationModel( 2 ));
flag = m->productoVendido( id, cant );
inside of the method productoVendido I get SegFault:
bool MProductos::productoVendido( QVariant id, QVariant cantidad )
{
qDebug( "Actualizando stock por venta" );
QModelIndex indice = index( id.toInt(), 6, QModelIndex() ); /// Here I get segfault
if( !indice.isValid() )
{
qDebug( "Error de indice al intentar actualizar productos! - indice invalido" );
return false;
}
QVariant cantAnterior = this->data( this->index( id.toInt(), 6 ), Qt::EditRole );
QVariant cantActual = QVariant::fromValue( cantAnterior.toDouble() - cantidad.toDouble() );
return this->setData( this->index( id.toInt(), 6 ), cantActual );
}
It's correct the using that I geave to the pointer o shud I make a new instance of the model?
Thanks:o
MProductos *m = qobject_cast<MProductos *>(this->relationModel( 2 ));
flag = m->productoVendido( id, cant );
inside of the method productoVendido I get SegFault:
bool MProductos::productoVendido( QVariant id, QVariant cantidad )
{
qDebug( "Actualizando stock por venta" );
QModelIndex indice = index( id.toInt(), 6, QModelIndex() ); /// Here I get segfault
if( !indice.isValid() )
{
qDebug( "Error de indice al intentar actualizar productos! - indice invalido" );
return false;
}
QVariant cantAnterior = this->data( this->index( id.toInt(), 6 ), Qt::EditRole );
QVariant cantActual = QVariant::fromValue( cantAnterior.toDouble() - cantidad.toDouble() );
return this->setData( this->index( id.toInt(), 6 ), cantActual );
}
It's correct the using that I geave to the pointer o shud I make a new instance of the model?
Thanks:o