Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    qlist error qpoint error passing c
    3
    4
    2578
    Loading More Posts
    • 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
      metty last edited by metty

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • A
          alex_malyu last edited by alex_malyu

          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 Reply Quote 0
          • M
            metty last edited by

            super, thank you! that solved my litttle problem.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post