Important: Please read the Qt Code of Conduct -

Multiplatform project file organization: Separate "Upstream" project for core functions?

  • Hi, I've developed a C++ Qt desktop application, and I want to port it to Android, and eventually iOS. I'm sure that some of my code will have to be repurposed for the different UI layout that i'll setup on mobile, but there are definitely some functions that will work exactly the same, such as functions that crunch strings or generate save/cache files. How should I go about organizing these common functions so that they're all stored in headers that don't pertain to a specific Qt project? Do people commonly run into this problem when porting their projects to other platforms?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The most common is to cleanly separate the UI and the core logic. Then you can build/specialise your UI for the target platform. A bit like the model view paradigm where the data and it representation are clearly separated.

  • Hi.
    When I have to write an application for mobiles too I use Qml.
    The code is the same except one function for to calculate the points for inch.
    So the code is the same for desktop and mobiles.

  • @SGaist Good point, I see the advantages of model-based UI elements now. Do you have an example of a cross-platform project's file structure on hand? Do some people have a separate git repo for their core logic?

  • Lifetime Qt Champion

    Unless you are re-using your core libraries in several project, it's pretty rare to have it in a separate repo.

    Hover you can have several sub-projects. For example one for a library containing your core logic and one for the application itself.

Log in to reply