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 );
MProductos *m = qobject_cast<MProductos *>(this->relationModel( 2 ));
flag = m->productoVendido( id, cant );
To copy to clipboard, switch view to plain text mode
inside of the method productoVendido I get SegFault:
{
qDebug( "Actualizando stock por venta" );
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 );
}
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 );
}
To copy to clipboard, switch view to plain text mode
It's correct the using that I geave to the pointer o shud I make a new instance of the model?
Thanks
Bookmarks