Question

Depending on the regional settings, the CSV separator (or the list separator) might be ; instead of ,, which, at least on Windows depends on the Regional Settings.

Is there a cross-platform way to detect what the CSV separator is with Qt?

If no cross-platform way is available, is there a Windows-specific way?

Était-ce utile?

La solution

There is QLocale::groupSeparator():

QChar separator = QLocale().groupSeparator();

Edit:

But that it not a correct answer. Group separator is a character used in long numbers between number groups, for example: "1,234.56". In that example group separator is comma and decimal separator is period.

It seems that the QLocale doesn't contain list separator at all. You might try to make a guess according to what decimal separator is used. If decimal separator is . then use , as a CSV separator, if decimal separator is , then use ; as a CSV separator. But I don't know if that covers all languages.

Autres conseils

For Windows, you can use GetLocaleInfo API to read the list separator.

GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLIST, szBuf, sizeof(szBuf));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top