Generate assert failure when qmodelindex is put into qdatastream...

  • Hi,

    I am trying to put qmodelindex into qdatastream and I get the following error:

    What should I do?

    < source >
    QVariant v(model_Idx);
    QByteArray ba;
    QDataStream ds(&ba, QIODevice::ReadWrite);

    ds << v;    

    Debug Error!
    Module : 5.7.1
    File : global\gglobal.cpp
    ASSERT failure in QVariant::save "Invalid type to save", file kernel\qvariant.cpp, line 2144


  • Qt Champions 2017

    I don't think QModelIndex storing in stream is supported. Since save operation returns false for QModelIndex, it must be crashing. May be you can get the row,column values from QModelIndex and save them in stream. Also as side note, it is not a good idea to store the QModelIndex. See the warning message in Qt documentation for QModelIndex.

Log in to reply