Results 1 to 3 of 3

Thread: relationalModel() pointer and segfault

  1. #1
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question relationalModel() pointer and segfault

    Using qt4 with a QSqlRelationalTableModel, if I try to use one method of the relational model with:

    Qt Code:
    1. MProductos *m = qobject_cast<MProductos *>(this->relationModel( 2 ));
    2. flag = m->productoVendido( id, cant );
    To copy to clipboard, switch view to plain text mode 
    inside of the method productoVendido I get SegFault:
    Qt Code:
    1. bool MProductos::productoVendido( QVariant id, QVariant cantidad )
    2. {
    3. qDebug( "Actualizando stock por venta" );
    4. QModelIndex indice = index( id.toInt(), 6, QModelIndex() ); /// Here I get segfault
    5. if( !indice.isValid() )
    6. {
    7. qDebug( "Error de indice al intentar actualizar productos! - indice invalido" );
    8. return false;
    9. }
    10. QVariant cantAnterior = this->data( this->index( id.toInt(), 6 ), Qt::EditRole );
    11. QVariant cantActual = QVariant::fromValue( cantAnterior.toDouble() - cantidad.toDouble() );
    12. return this->setData( this->index( id.toInt(), 6 ), cantActual );
    13. }
    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
    Last edited by tranfuga25s; 30th July 2007 at 15:33. Reason: updated contents

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: relationalMode() pointer and segfault

    Either 6 is an out of range column or id is not valid.
    Could you see what id.isNull() and id.isValid() return?

    Regards

  3. #3
    Join Date
    Aug 2006
    Location
    Some where in Argentina
    Posts
    23
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: relationalModel() pointer and segfault

    No, I cant, because the program gets segfault in that exact point.
    The column 6 exists, I've used it on the constructor of the model:

    Qt Code:
    1. setHeaderData( 6, Qt::Horizontal, tr( "Stock" ) );
    To copy to clipboard, switch view to plain text mode 
    and id, comes from the original model, I get it with:
    Qt Code:
    1. QVariant id = QSqlTableModel::data( this->index( fila, 2 ) );
    To copy to clipboard, switch view to plain text mode 
    so, seems that the id it's valid.
    Even I change the qobject_cast<.... with a "new" operator, still getting invalid index in every situation.

    I'm using sqlite. May be that the problem, the method venderProducto( ... ) is called from inside another model. May be that i cant update that data because, the original model is locking the db??
    Last edited by tranfuga25s; 30th July 2007 at 15:29. Reason: updated contents

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.