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 at/operator[] and const
Forum Updated to NodeBB v4.3 + New Features

QVector at/operator[] and const

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.5k 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.
  • A Offline
    A Offline
    apollo74
    wrote on last edited by
    #1

    [EDIT: split off "this thread":http://developer.qt.nokia.com/forums/viewthread/5340 of rickbkis as it's a similar, though different problem, Volker]

    Hi guys, I'm not sure if mine is the same problem as rickbkis' but I wanted to try here first before creating a new thread.
    I'm trying to plot a vector of floats with QGLWidget so I have created a vector first to put all my points in there:
    @private: QVector<QVector3D> vertices;@
    And a public function that receives data from an external widget:
    @public:
    void plot(float *data, int size){
    for(int i=0; i<size; i++)
    vertices.at(i).setY(data[i]);
    updateGL();
    }@
    But I'm getting the following error:
    passing 'const QVector3D' as 'this' argument of 'void QVector3D::setY(qreal)' discards qualifiers
    Do you know where exactly is my mistake located and how should I sove it? Thanks for any help,
    Boris

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      It's the use of "QVector::at() ":http://doc.qt.nokia.com/4.7/qvector.html#at. The docs state clearly, that it returns a const reference:

      @
      const T & QVector::at ( int i ) const
      @

      use

      @
      vertices[i]
      @

      in order to get a non-const reference. Watch out, value(i) returns a value, not a reference!

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        The same is true for other containers as well.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          apollo74
          wrote on last edited by
          #4

          Thanks Volker, did it and worked... I still have some problems understanding how to code, programming is not my main stuff. Thanks again.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            I recommend to have a look at some of the C++ tutorials. It helps a lot - not only Qt related.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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