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
QtWS25 Last Chance

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 last edited by metty
    #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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 last edited by alex_malyu
        #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 last edited by
          #4

          super, thank you! that solved my litttle problem.

          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