Results 1 to 4 of 4

Thread: Cannot use QRect::setWidth

  1. #1
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Cannot use QRect::setWidth

    When I try to set the width of a modified QDockWidget

    Qt Code:
    1. int iWidth = 500;
    2. this->geometry().setWidth(iWidth);
    To copy to clipboard, switch view to plain text mode 

    I get the following error.

    passing 'cost QRect' as 'this' argument of 'void QRect::setWidth(int)' discards qualifier
    I have no idea what that error means and why I can't use such a simple function.

  2. #2
    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: Cannot use QRect::setWidth

    It means you are trying to modify an object that is const.
    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.


  3. #3
    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: Cannot use QRect::setWidth

    passing 'const QRect' as 'this' argument of 'void QRect::setWidth(int)' discards qualifier
    Contains two clues. You have a constant object that you are trying to use a non-const method on. The "discards qualifier" refers to attempting to discard the "const". This is an error and basic C++.

    QWidget::geometry() is defined:
    Qt Code:
    1. const QRect & geometry () const
    To copy to clipboard, switch view to plain text mode 
    You cannot modify a const QRect.

    You can modify the geometry through the QWidget::setGeometry() method.

  4. The following user says thank you to ChrisW67 for this useful post:

    WilliamSpiderWeb (4th March 2011)

  5. #4
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cannot use QRect::setWidth

    Thank you,
    that was really stupid...

    When I read your post I remembered that I used setGeometry() before.

Similar Threads

  1. AddText to QRect on QGraphicsView
    By mohini in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 21:43
  2. Get QRect of a widget using mouseevent
    By arpspatel in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2010, 04:19
  3. difference of QRect and QRectF
    By gbmtoday in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 22:52
  4. Replies: 11
    Last Post: 17th January 2009, 09:06
  5. Move QCompleter on QRect x,y
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 10:33

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.