[Development] The life of a file name and other possibly mal-encoded strings on non-Windows systems

Thiago Macieira thiago.macieira at intel.com
Mon Oct 6 20:45:28 CEST 2014


On Monday 06 October 2014 13:30:29 Kuba Ober wrote:
> > This was discussed to exhaustion in Qt 5's development process. The
> > conclusion is to remain at status quo since there is no good, technical
> > solution.
>
> I’d think that the solution could be to use a dedicated class for file
> names, perhaps with a base class for uninterpreted platform strings.

We thought about that. The problem comes when you need to pass the file name 
through other means besides the file management functions.

How do you write it to a file using QIODevice? How do you write it to a file 
using QTextStream?

How do you pass it on the command-line? Mind you, QProcess takes a QStringList 
for arguments.

What should QCommandLineParser do? Assume that all arguments a QFileName?

What happens when you display the file name for the user in a text edit? What 
happens if the user edits the text?

Will we replace all of the QString-based API with QFileName instead? QPixmap, 
QLibrary, QPluginLoader, etc.

And how will you teach people to concatenate using the correct functions, 
instead of manipulating using QString?

Also remember that everything is the opposite on Windows: the file names are 
really UTF-16 and cannot be encoded in the locale's 8-bit encoding.

> So, I’m specifically thinking of:
> 
> 1. Retaining platform-specific representation of a file name in a class like
> QFileName (it’d be a QString wrapper on Windows, for example).
> 
> 2. Sending it out to `QTextStream(stdout)`, and inputting it from
> `QTextStream(stdin)`.
> 
> 3. Using the platform representation in addition to visible representation
> in the filesystem model.
> 
> Would something like that have any chance of getting accepted into Qt 6, if
> done “properly”? Obviously I haven’t thought out the details yet and there
> may be a need for several prototypes before it turns into anything remotely
> acceptable.

Chance, yes, if you can fix the rest of the problems.

This is a bigger problem than you realise.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list