Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous
Forum Updated to NodeBB v4.3 + New Features

call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 958 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samzhcs1
    wrote on last edited by
    #1

    Hi, the statement:
    tokFormula = tokFormula.replace('+','-',Qt::CaseInsensitive);

    I got a warning:
    call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous.
    If I change the statement to:
    tokFormula = tokFormula.replace("+","-",Qt::CaseInsensitive);
    then it works well.

    But in QT document:
    QString &QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
    This function overloads replace().
    Replaces every occurrence of the character before with the character after and returns a reference to this string.

    Paul ColbyP 1 Reply Last reply
    0
    • S samzhcs1

      Hi, the statement:
      tokFormula = tokFormula.replace('+','-',Qt::CaseInsensitive);

      I got a warning:
      call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous.
      If I change the statement to:
      tokFormula = tokFormula.replace("+","-",Qt::CaseInsensitive);
      then it works well.

      But in QT document:
      QString &QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
      This function overloads replace().
      Replaces every occurrence of the character before with the character after and returns a reference to this string.

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @samzhcs1,

      call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous.

      At a glance, I'd say the reason this is ambiguous is because there is no QString::replace overload that takes char - you're probably expecting the overload that takes QChar (which is not char) but the compiler cannot make that assumption.

      Put another way, the compiler could just as validly turn your char arguments into QChar or QString - obviously we can tell from the names that you probably want QChar, but the compiler doesn't know this.

      So, try converting your char argument to QChar explicitly, like:

      myString.replace(QChar(char1), QChar(char2), ...);
      

      Cheers.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved