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. QList and QPoints error: passing 'const QPointF' as 'this' argument of 'qreal& QPointF::rx()' discards qualifiers
Forum Update on Monday, May 27th 2025

QList and QPoints error: passing 'const QPointF' as 'this' argument of 'qreal& QPointF::rx()' discards qualifiers

Scheduled Pinned Locked Moved General and Desktop
qlisterrorqpointerror passing c
4 Posts 3 Posters 3.0k 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.
  • M Offline
    M Offline
    metty
    wrote on 5 Aug 2015, 13:59 last edited by metty 8 May 2015, 14:00
    #1

    Hello,

    I have a QList with QPoints:
    QList<QPointF> points;

    Why does this work:
    qDebug()<<points.first().rx();

    and this not:?
    qDebug()<<points.at(0).rx();

    thank you for you help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Aug 2015, 20:39 last edited by
      #2

      Hi,

      Because at returns a const reference while first can either return a reference or a const reference and rx is a non const method of QPointF.

      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
      • A Offline
        A Offline
        alex_malyu
        wrote on 5 Aug 2015, 23:29 last edited by alex_malyu 8 May 2015, 23:30
        #3

        I just want to add that you should not use non const methods when you can use const methods anyway.

        qDebug()<<points.at(0).x();

        1 Reply Last reply
        0
        • M Offline
          M Offline
          metty
          wrote on 10 Aug 2015, 06:59 last edited by
          #4

          super, thank you! that solved my litttle problem.

          1 Reply Last reply
          0

          4/4

          10 Aug 2015, 06:59

          • Login

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