Results 1 to 3 of 3

Thread: QVector.push_back problem...

  1. #1
    Join Date
    Jan 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QVector.push_back problem...

    Hello to all,

    i've used to be a programmer but i'ts been a long time (more than 8 years) since i've done any programming. I'm now getting back in shape by learning to program with Qt4.

    Here's my problem so far with the following code:
    In the header file:
    Qt Code:
    1. QVector<QPoint> m_cheatTrajectoryPt;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. m_cheatTrajectoryPt.push_back(QPoint(qRound(x), height() - 1 - qRound(y)));
    To copy to clipboard, switch view to plain text mode 
    And here is the compile error that puzzles me:
    Qt Code:
    1. cannonfield.cpp: In member function 'QRect CannonField::shotRect() const’:
    2. cannonfield.cpp:134: erreur: passing 'const QVector<QPoint>' as ‘this’ argument of ‘void QVector<T>::push_back(const T&) [with T = QPoint]’ discards qualifiers
    To copy to clipboard, switch view to plain text mode 

    Any help would be greatly appreciated!

    Thanks!

    Luc

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVector.push_back problem...

    Hi,
    Quote Originally Posted by luche View Post
    I'm now getting back in shape by learning to program with Qt4.
    Remember that in order to be successful with Qt you need to know C++. Qt is not a programming language.

    cannonfield.cpp: In member function 'QRect CannonField::shotRect() const’:
    cannonfield.cpp:134: erreur: passing 'const QVector<QPoint>' as ‘this’ argument of ‘void QVector<T>:ush_back(const T&) [with T = QPoint]’ discards qualifiers
    You are trying to modify a member variable (m_cheatTrajectoryPt) in a const method (CannonField::shortRect). A const method shouldn't change the state of an object.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: QVector.push_back problem...

    Quote Originally Posted by jpn View Post
    Hi,

    Remember that in order to be successful with Qt you need to know C++. Qt is not a programming language.


    You are trying to modify a member variable (m_cheatTrajectoryPt) in a const method (CannonField::shortRect). A const method shouldn't change the state of an object.
    I'm rusty

    Thanks for your help

Similar Threads

  1. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.