Results 1 to 4 of 4

Thread: Qt won't recognize QString::replace function.

  1. #1
    Join Date
    Mar 2020
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Qt won't recognize QString::replace function.

    Hello
    I've got trouble with this line of code:

    Qt Code:
    1. expr.replace(*start - 1, *end - *start - 1, result_s);
    To copy to clipboard, switch view to plain text mode 

    where *start and *end are pointers to integers(table adresses), and result_s is a string.

    The error message: no matching member function for call to 'replace'.

    This is a precise function I meant to call: https://doc.qt.io/qt-5/qstring.html#replace .

    Using Qt Creator 4.11.0 with C++.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt won't recognize QString::replace function.

    and result_s is a string
    A std:: string, a char * pointer to a C string, or a QString? If it is not a QString, then there is no match to a QString member function.

    Another problem could be that if *start and *end are not "int" types (you said they were addresses), and so the results of the expressions are something larger, like unsigned long long. Again, there is no match. Forcing *start and *end to "int" via a cast could be an error too - forcing an address to an int means that the replace() method isn't actually receiving the true address but a truncated, incorrect value.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt won't recognize QString::replace function.

    Quote Originally Posted by d_stranz View Post
    A std:: string, a char * pointer to a C string, or a QString? If it is not a QString, then there is no match to a QString member function.

    Another problem could be that if *start and *end are not "int" types (you said they were addresses), and so the results of the expressions are something larger, like unsigned long long. Again, there is no match. Forcing *start and *end to "int" via a cast could be an error too - forcing an address to an int means that the replace() method isn't actually receiving the true address but a truncated, incorrect value.
    Sorry d_stranz but if start is a "pointer to int" so *start gives int value. Maybe Warumato would show more code, especially start, end and result_s.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt won't recognize QString::replace function.

    Sorry d_stranz but if start is a "pointer to int" so *start gives int value.
    The OP's description is unclear. Yes, he said "pointers to ints", but then he also said "table addresses". I understood that to mean the de-referenced pointers were themselves addresses of memory locations, and those would probably be larger than int.

    Some more code would definitely help. I am isolated at home, and unfortunately my crystal ball is at the office.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QString unicode replace
    By trallallero in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2012, 14:57
  2. [solved]QString.replace()
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2011, 09:15
  3. QString - find and replace text
    By graciano in forum Newbie
    Replies: 3
    Last Post: 24th January 2009, 20:35
  4. QString::replace() with QRegExp capture modification
    By Lykurg in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2008, 09:50
  5. How to recognize a letter from a Qstring?
    By luffy27 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2007, 19:22

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.