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 merge
Forum Updated to NodeBB v4.3 + New Features

QVector merge

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.7k 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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    I would like to "merge" two QVector of the same size into one third QVector. Example:

    @
    QVector<qreal> x;
    QVector<qreal> y;

    // fill both x and y with the same number of items

    QVector<QPointF> pos; // composed of x and y values
    @

    How to achieve that?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean something like

      @for (int i = 0 ; i < x.size() ; ++i) {
      pos << QPointF(x.at(i), y.at(i));
      }@

      ?

      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
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        Exactly, but I'm looking for something better than the trivial method - if exists.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mikeosoft
          wrote on last edited by
          #4

          I'm not in a position to test this, but as a quick response, I think you can use the +=, or the the + operator or possibly the append() method.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What do you mean by better ?

            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
            • _ Offline
              _ Offline
              _Mark_
              wrote on last edited by
              #6

              I'd like to avoid cycling over all the elements.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Then how would you create a new object of a different class that uses one element of both vectors ?

                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
                • _ Offline
                  _ Offline
                  _Mark_
                  wrote on last edited by
                  #8

                  Well, the final goal is to easily handle a progressive graph.
                  I'm using qwt and the qwtdataseries class requires a QVector<QPointF>.

                  I was going to create a "constant" (I mean I won't change its values) QVector for x axis: 0..1..2..3..4 and so on.
                  The y QVector will be instead pushed and popped every sample received.
                  In this way I easily create a scrolling graph in real-time.

                  1 Reply Last reply
                  0

                  • Login

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