how to use switch with an element of a string in qt?

1

What happens is that I am communicating by serial port and I receive a string (example a210223), but to sort the data in the interface I have to identify the initial letter and pass it by a switch to identify and display them. I divide them with the following instructions:

k=serial->readAll();

QString d=k.left(1);

QString b=k.mid(1,3);

QString c=k.mid(4,7);

But trying to use switch with d (for the first data) tells me that it is not a integer .

    
asked by rasengan um 03.07.2018 в 18:09
source

1 answer

1

Assuming that k is of type QString you can try something like this:

QChar c = k.front();
switch( c.unicode() )
{
  case 'a':
    // ...
}
    
answered by 04.07.2018 / 08:17
source