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. [SOLVED] Error with setRect in QRect
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Error with setRect in QRect

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k 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.
  • guidupasG Offline
    guidupasG Offline
    guidupas
    wrote on last edited by
    #1

    Hello all!

    I have a QRect and when I try to setRect it return this error

    /QT/Projetos/VisaoFinanceira/fluxocaixawidget.cpp:174: error: member function 'setRect' not viable: 'this' argument has type 'const QRect', but function is not marked const
    fluxoRect.at(i).setRect(7,7,7,7);

    Thanks.

    Here is the code:
    @
    QList<QRect> fluxoRect;

    fluxoRect.append(QRect(0,0,0,0));

    fluxoRect.at(i).setRect(7,7,7,7);
    @

    Att.
    Guilherme Cortada Dupas

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Saugglocke
      wrote on last edited by
      #2

      Hey,

      look at the definition of the at method:
      const T & at(int i) const

      QList returns a const reference to your QRect, hence you're not allowed to alter it.

      You have to do something like this:
      @ QList<QRect> fluxoRect;

      fluxoRect.append(QRect(0,0,0,0));
      
      QRect r = fluxoRect.takeAt(i);
      r.setRect(7, 7, 7, 7);
      fluxoRect.replace(i, r);@
      

      bb

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

        Hi,

        at is a constant function so you can't modify it's returned value like that.

        Either use the value method or the [] operator.

        You can also take the rect modify it and replace the original value with the new value.

        Hope it helps

        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
        • guidupasG Offline
          guidupasG Offline
          guidupas
          wrote on last edited by
          #4

          Thank you for the replies Saugglocke and SGaist

          It worked.

          @
          fluxoRect.at(i).replace(QRect(7,7,7,7));
          @

          Att.
          Guilherme Cortada Dupas

          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