Ulfric Storm
Ulfric Storm

Reputation: 129

Loop over a QString and do a comparison each time with QChar

I have a QString in which i want to search for a sign. So i tried to do this with

if(inLineEditDisplay[i]=="+")

but without success. The error i get is

error: conversion from 'const char [2]' to 'QChar' is ambiguous

What's the correct way to compare a QChar with a string?

Upvotes: 1

Views: 4818

Answers (1)

Jan Kundrát
Jan Kundrát

Reputation: 3816

That's because you're comparing one unicode character (QChar) with a C-style string literal (because "+" is actually an array of two chars, the '+' and the 0 byte for termination).

Use this:

if (inLineEditDisplay[i] == QLatin1Char('+'))
  ...

Upvotes: 2

Related Questions