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 assignment operator ?
QtWS25 Last Chance

QVector assignment operator ?

Scheduled Pinned Locked Moved Solved General and Desktop
qvector
10 Posts 3 Posters 1.9k Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 3 Jun 2019, 19:36 last edited by
    #1

    Hey

    I have anniying issue. If I run my app in debug mode everything works, but if I run in release mode I get a crash. As far as I can tell I'm creating all pointers/null/initialize stuff properly but I'm still having issues. So far debuging lead me to believe that the issues is in copy constructor when I do :

    QVetor<class> x = src.x;

    I think when this happens, the copied classes which every they are made do not copy properly and manage their pointers. Even tho I have all default/copy and assignment constructor implemented... I think. Not sure but debuging this is hard when I cant actually run a debug...

    Can any1 hint me what functions would qt call when executing the above command?

    TIA

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Jun 2019, 20:00 last edited by
      #2

      Hi,

      Why can't you run in debug mode ?
      What is stored in x ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dariusz
        wrote on 3 Jun 2019, 20:06 last edited by Dariusz 6 Mar 2019, 20:08
        #3

        Debug mode runs fine, but it does not crash. Release mode crashes. I narrowed it down to vector=vector assignments I think... unsure. Its all black magic without debug.

        QVector<obj> x = src.x;

        class obj{
        QVector<obj> x;
        }

        A 1 Reply Last reply 3 Jun 2019, 20:15
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Jun 2019, 20:13 last edited by
          #4

          What if you print the content of src.x ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Dariusz
            3 Jun 2019, 20:06

            Debug mode runs fine, but it does not crash. Release mode crashes. I narrowed it down to vector=vector assignments I think... unsure. Its all black magic without debug.

            QVector<obj> x = src.x;

            class obj{
            QVector<obj> x;
            }

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 3 Jun 2019, 20:15 last edited by
            #5

            @Dariusz

            Debug mode runs fine, but it does not crash. Release mode crashes. I narrowed it down to vector=vector assignments I think... unsure. Its all black magic without debug.

            So true. I'm just throwing Address Sanitizer and Valgrind in the ring. These tools might help finding issues like yours.

            Or try to compile your code with other compiler or on other platform. It might already crash in debug then.

            Good luck!

            Qt has to stay free or it will die.

            1 Reply Last reply
            1
            • D Offline
              D Offline
              Dariusz
              wrote on 3 Jun 2019, 20:35 last edited by
              #6

              Hey

              Ok I managed to solve it. Gotta say as much as I love QVector...some times I just want to..........

                  mChildren.resize(rhs.mChildren.size());
                  for (int x = 0; x < rhs.mChildren.size(); ++x) {
                      mChildren[x].loadFromBox(rhs.mChildren[x]);
                  }
              

              Ended up doing this to fix it... Im afraid of everything now !

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 3 Jun 2019, 20:36 last edited by
                #7

                So the class contained in that QVector can't be copied ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dariusz
                  wrote on 3 Jun 2019, 20:41 last edited by Dariusz 6 Mar 2019, 20:41
                  #8

                  No idea, I had implemented class(const class&src) as well as operator= and class(){}.
                  I though all I needed was default constructor, copy constr and assign operator but apprently I was missing something...

                  or when I was doing vec=src.vec. I was just adding ref counter to data inside other class and not doing deep copy? No idea... I just know it took 7h to debug :- (

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 3 Jun 2019, 20:42 last edited by
                    #9

                    What does loadFromBox compared to your copy constructor and assignment operator ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    D 1 Reply Last reply 3 Jun 2019, 22:14
                    0
                    • S SGaist
                      3 Jun 2019, 20:42

                      What does loadFromBox compared to your copy constructor and assignment operator ?

                      D Offline
                      D Offline
                      Dariusz
                      wrote on 3 Jun 2019, 22:14 last edited by
                      #10

                      @SGaist does the same as copy at the end. I did not trust vec=vec. So I ended up doing it "Manually". Will try to go back to native c++ calls/overload/ once I know I dont have other bugs influencing the source...

                      1 Reply Last reply
                      0

                      6/10

                      3 Jun 2019, 20:35

                      • Login

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