Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QVector copy



  • I can't copy correctly the qvector data, everything i did, it crash at some point.
    Copy constructor does work, but for some reason, whne i do some more copyes, at some point it crash, and i have no idea why. What should i do? I have a QVector, inside another QVector, and idk how should i copy it.

    Data, is a object passed to the copy constructor.

        for(int i = 0; i < data.sequence.count(); i++)
        {this->sequence.append(data.sequence.data()[i].mid(0, data.sequence.data()[i].count()));}
    
    

  • Moderators

    @Loc888 said in QVector copy:

    at some point it crash, and i have no idea why.

    Run your program in the debugger, and look at the Stack Trace when it crashes. It will show you why.

    Data, is a object passed to the copy constructor.

    for(int i = 0; i < data.sequence.count(); i++)
    {this->sequence.append(data.sequence.data()[i].mid(0, data.sequence.data()[i].count()));}
    

    Please show us the class/struct definitions for all of the types in your code.

    data.sequence.data()[i]

    This looks a bit strange.

    Are you storing pointers to vectors? That is not necessary.

    .mid(0, data.sequence.data()[i].count()))

    This looks redundant.

    vec.mid(0, vec.count()) simply returns a copy of vec.



  • I fixed it, it's working fine. it wasn't even a QVector issue, but another pointer was crashing the program randomly


  • Moderators

    @Loc888 said in QVector copy:

    I fixed it, it's working fine.

    Great!

    another pointer was crashing the program randomly

    This is a good example of why you should look for opportunities to avoid pointers.

    As I said in my previous post, you don't need to store vector pointers, QVector<T>*. Just store the actual vector, QVector<T>.


Log in to reply