Results 1 to 5 of 5

Thread: Error with setRect in QRect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Error with setRect in QRect

    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:
    Qt Code:
    1. QList<QRect> fluxoRect;
    2.  
    3. fluxoRect.append(QRect(0,0,0,0));
    4.  
    5. fluxoRect.at(i).setRect(7,7,7,7);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error with setRect in QRect

    The at() function returns a constant reference to a QRect in the list. You cannot modify a constant QRect. Try using the list's operator[]() to get a non-const reference.

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Error with setRect in QRect

    Thanks for the reply

    I have solved it.

    Qt Code:
    1. fluxoRect.at(i).replace(QRect(7,7,7,7));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error with setRect in QRect

    I don't think the code you posted is going to work... You probably meant:

    Qt Code:
    1. fluxoRect.replace(i, QRect(7,7,7,7));
    To copy to clipboard, switch view to plain text mode 

    Alternatively you could have done:

    Qt Code:
    1. fluxoRect[i] = QRect(7,7,7,7);
    To copy to clipboard, switch view to plain text mode 

    or
    Qt Code:
    1. fluxoRect[i].setRect(QRect(7,7,7,7));
    To copy to clipboard, switch view to plain text mode 

    which use the non-const variant of [] operator.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Error with setRect in QRect

    wysota, thank you for your reply

    Qt Code:
    1. fluxoRect.replace(i, QRect(7,7,7,7));
    To copy to clipboard, switch view to plain text mode 

    worked fine.

Similar Threads

  1. QRect with border?
    By BettaUseYoNikes in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2011, 00:56
  2. Cannot use QRect::setWidth
    By WilliamSpiderWeb in forum Newbie
    Replies: 3
    Last Post: 4th March 2011, 15:45
  3. Get QRect of a widget using mouseevent
    By arpspatel in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2010, 04:19
  4. setRect vs boundingRect
    By zgulser in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2009, 00:23
  5. how to set setRect for proxy widget
    By wagmare in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2008, 13:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.