What is QStringConverter::LastEncoding?
Unsolved
General and Desktop
-
In a course I came across the lines:
QTextStream stream(&file); stream.setEncoding(QStringConverter::LastEncoding);
where file is a QFile. The program runs fine, but I could not find any definition of LastEncoding.
Does anyone know what it is? Thanks!
-
@Jeroen537 The enum concerned is:
enum Encoding { Utf8, Utf16, Utf16LE, Utf16BE, Utf32, Utf32LE, Utf32BE, Latin1, System, LastEncoding = System };
The member LastEncoding is an alias for whatever encoding is the last in the enum, in this case System. Having such an alias is an enabler to iteration over all numeric values in the enum (see for example this SO answer). Qt uses it in an array to enable encodingForName() to do a string-to-enum value lookup.
In your code snippet the author appears to be assuming that this will always be System. IMHO this, while true at the moment, is an unsafe assumption. LastEncoding is not documented for a reason.