Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. What are good coding patterns to avoid "conditional compile clutter" ( #ifdef Q_OS_ANDROID ) to support multiple platforms ?
Forum Updated to NodeBB v4.3 + New Features

What are good coding patterns to avoid "conditional compile clutter" ( #ifdef Q_OS_ANDROID ) to support multiple platforms ?

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 2.1k 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.
  • E Offline
    E Offline
    EdOfTheMountain
    wrote on last edited by
    #1

    Problem: There will always be a problem to solve that will require use of a native API.

    Example: I have a JNI interface that sends email with attachments on Android. I will need another implementation for iOS, another for OSX and Linux, another for Windows, etc.

    Solutions?
    What are good coding patterns to avoid "conditional compile clutter"? Can anyone point me to some code examples?

    An interface class with implementation for Android, iOS, Linux, OSX, and Windows?

    Thanks in advance for ideas and suggestions,

    -Ed

    1 Reply Last reply
    0
    • E Offline
      E Offline
      EdOfTheMountain
      wrote on last edited by
      #2

      The bug report below is what got me started thinking about ways to avoid ifdef's:

      QTBUG-29477
      Remove Q_OS_ANDROID checks where possible

      There are a lot of #ifdef Q_OS_ANDROID around, e.g. in the style code, and that's not really the way platform integrations are done anymore. We need to see if they are necessary. In the style code it would make sense if they are inside the android style instead of spread around.

      https://bugreports.qt-project.org/browse/QTBUG-29477

      1 Reply Last reply
      0
      • benlauB Offline
        benlauB Offline
        benlau
        Qt Champions 2016
        wrote on last edited by
        #3

        You may implement your code by using bridge design pattern. Some Qt classes also use this design pattern.

        "Bridge pattern - Wikipedia, the free encyclopedia":http://en.wikipedia.org/wiki/Bridge_pattern

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

          Hi,

          Depending on the amount of code (e.g. complete methods), you can create a yourcoolclass_nameofplatform.cpp file where you'll have the implementation details that you want to separate and you'll compile the correct file for a given platform.

          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
          • E Offline
            E Offline
            EdOfTheMountain
            wrote on last edited by
            #5

            Thank you both for the suggestions!

            -Ed

            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