Multiple OSs, one codebase, Part 3 - Files

October 3, 2026 Qt Software

Here's another pain point you'll need to navigate,

Windows and Linux share a nice, simple way to handle file paths and names: QStrings. You can manipulate them, add to them, everything you might think you need to do to get to the files you need.

WASM and Android don't like filenames. Or directory paths. or appending to what they give you. And they like to use QUrls. So bite the bullet and use QUrls and stop messing with the filenames. I ifdef around any directory saving/manipulating I think I need on the desktop OSs.

The only gotcha to look out for in handling QUrls instead of QStrings is that Windows doesn't like QUrls for local files. Just use this magic:

 QFile file(url.isLocalFile() ? url.toLocalFile() : url.toString());

Good luck, almost to the end of this. I think there is only one more pain point I have hit. It can really throw you under the bus if you don't write around it. See you next time!

Quoth!

Comments (0)

No comments yet. Be the first hero to speak up.

Leave a comment