Results 1 to 3 of 3

Thread: passing as 'this' argument of discards qualifiers

  1. #1
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default passing as 'this' argument of discards qualifiers

    Hi , I have a problem when compile following code:
    Qt Code:
    1. for(int i=0;i<curConnections.size();++i)
    2. {
    3. if (curConnections.at(i).Descriptor()==connName)
    4. {
    5. curConnections.at(i).sendCmd(cmd);
    6. break;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Compiler complains:
    error: passing 'const ConnConnection' as 'this' argument of 'void ConnConnection::sendCmd(const QString&)' discards qualifiers

    Then I use following it compiles OK.

    Qt Code:
    1. curConnections[i].sendCmd(cmd);
    To copy to clipboard, switch view to plain text mode 

    I am not quite get what's the difference of these 2 lines of code.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: passing as 'this' argument of discards qualifiers

    at() is a const function and returns a const object. operator[]() is non-const.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. The following 2 users say thank you to franz for this useful post:

    iskenderoguz (23rd June 2014), yyiu002 (22nd June 2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing as 'this' argument of discards qualifiers

    many thanks

Similar Threads

  1. argument parsing
    By deeee in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2010, 22:21
  2. Trouble passing an argument
    By benlyboy in forum Newbie
    Replies: 5
    Last Post: 9th May 2010, 22:49
  3. const QStringList discards qualifiers
    By kandalf in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 18:09
  4. QtScript : passing array as argument into function
    By derek_r in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2007, 10:46
  5. Access Specifiers, Modifiers and Qualifiers
    By sunil.thaha in forum General Programming
    Replies: 4
    Last Post: 8th March 2006, 12:07

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.