Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVector copy

QVector copy

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Loc888
    wrote on last edited by
    #1

    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()));}
    
    
    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      4
      • L Offline
        L Offline
        Loc888
        wrote on last edited by
        #3

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

        JKSHJ 1 Reply Last reply
        1
        • L Loc888

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

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @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>.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved