Question

I'm trying to parse a QString character by character with a while loop, but I can't figure out how to parse an individual character to char type. Here's my code, I know it's not optimal:

QString temp = (QString)t[0];
int i = 1;

while (t[i] != " ");
{
    temp.append(t[i]);
    i += 1;
}

I've seen the casting with toLocal8bit function, but whatever I try I just cannot adapt it to my code.

Qt Creator shows this error:

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

in line with the while function call

Was it helpful?

Solution

Why don't you try that :

QString test = "test";


for(int i = 0; i< test.length(); i++)
{
    if (test.at(i) != " ")
        test.at(i).toLatin1();
}

OTHER TIPS

You can use C++ 11 range based for loop

for (auto chr : text)
{
    if (!chr.isDigit()) // for exmpl.
    return false; 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top