Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. [SOLVED] Managing cross-platform code repositories
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Managing cross-platform code repositories

Scheduled Pinned Locked Moved The Lounge
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goblincoding
    wrote on last edited by
    #1

    Hi everyone,

    This thread was lost during the server crash so if you're reading this again, you aren't experiencing deja vu :P

    I've been developing an application predominantly on Windows, but now want to start the port to Linux. However, certain GUI elements need tweaking for the new platform.

    What I'd like to know is what you reckon the "best practice" approach would be for keeping the core functionality in sync and avoiding duplication, while also managing the code that is unique to each platform?

    Before the previous thread disappeared into the ether, someone suggested compilation directives (which I'm not averse to). However, what I'd like to know is what the best way is to do this and with that I mean (1) if there is a way to add the #define to the Qt project file or (2) if one should use some kind of globalinclude.h file where you set your defines?

    Alternatively, is there a way to do it with version control techniques? I'm using Mercurial and initially considered branching, but realised that that would not solve the "duplicate shared code" problem as I'll then still have to update two or more separate branches whenever core functionality changes.

    Your input is appreciated.

    Thanks!

    http://www.goblincoding.com

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Here are multiple things that can be done. For little pieces of code you can simply use the
      @#if defined(Q_OS_WIN)
      #elif defined(Q_OS_MACX)
      #elif etc...
      #endif@

      construct.

      If you have bigger "implementation details" you can separate things in different cpp files one for each platform i.e. :
      mycoolwidget.cpp <- common implementation
      mycoolwidget_win.cpp <- windows specific stuff
      mycoolwidget_unix.cpp <- linux/os x stuff if both can use the same code
      etc...

      Then in your pro file, use scopes to build the correct set of files.
      If you need your own defines for a platform theres the DEFINES variable

      As for version control, I would avoid branches for that use case, you will indeed end with some code fragmentation unless you're adding a new platform, then it's best to start a new branch for that and once stable get it back in your main branch.

      You can also look at the Qt sources, since they do that for several platforms

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goblincoding
        wrote on last edited by
        #3

        Thanks a lot! This is exactly the entry point I was looking for.

        http://www.goblincoding.com

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Don't forget to update the thread's title to solved so other forum users may know that you have found what you were looking for :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved