Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do i run my app on any OS when the app includes Windows Api ?

How do i run my app on any OS when the app includes Windows Api ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.4k Views
  • 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by
    #1

    **Hi
    I am creating an app and i am creating it with windows api ( app includes windows api code ) now when i deploy my app how could i let my app run in any OS ? which means the windows api code should get converted to Mac api if ran in Mac same with other os ? **

    what is a signature ?? Lol

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

      Hi
      You will need to make the same code AGAIN for Mac.
      Then inside the program use defines to control what part of the code should be compiled.
      So when you compile your code on Mac with Xcode it will take that code instead.

      so slowly your code will become

      #ifdef _WIN32
         //define something for Windows (32-bit and 64-bit, this part is common)
         #ifdef _WIN64
            //define something for Windows (64-bit only)
         #endif
      #elif __APPLE__
          #include "TargetConditionals.h"
          #if TARGET_IPHONE_SIMULATOR
               // iOS Simulator
          #elif TARGET_OS_IPHONE
              // iOS device
          #elif TARGET_OS_MAC
              // Other kinds of Mac OS
          #else
          #   error "Unknown Apple platform"
          #endif
      #elif __linux__
          // linux
      #elif __unix__ // all unices not caught above
          // Unix
      #elif defined(_POSIX_VERSION)
          // POSIX
      #else
      #   error "Unknown compiler"
      #endif
      

      So then you wish all code could just be the same and hence Qt was born. :)

      So native programming is time consuming if you also want to be cross platform.

      AhtiA 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        You will need to make the same code AGAIN for Mac.
        Then inside the program use defines to control what part of the code should be compiled.
        So when you compile your code on Mac with Xcode it will take that code instead.

        so slowly your code will become

        #ifdef _WIN32
           //define something for Windows (32-bit and 64-bit, this part is common)
           #ifdef _WIN64
              //define something for Windows (64-bit only)
           #endif
        #elif __APPLE__
            #include "TargetConditionals.h"
            #if TARGET_IPHONE_SIMULATOR
                 // iOS Simulator
            #elif TARGET_OS_IPHONE
                // iOS device
            #elif TARGET_OS_MAC
                // Other kinds of Mac OS
            #else
            #   error "Unknown Apple platform"
            #endif
        #elif __linux__
            // linux
        #elif __unix__ // all unices not caught above
            // Unix
        #elif defined(_POSIX_VERSION)
            // POSIX
        #else
        #   error "Unknown compiler"
        #endif
        

        So then you wish all code could just be the same and hence Qt was born. :)

        So native programming is time consuming if you also want to be cross platform.

        AhtiA Offline
        AhtiA Offline
        Ahti
        wrote on last edited by
        #3

        @mrjj do i have to write code for Mac api from scratch ? isn't there any way to just write code for any api and then it gets converted to a particular Os's api automatically ?

        what is a signature ?? Lol

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          yes, that's what QPA (qt platform abstraction) does. If you use an OS API directly, however, how can you expect it to magically work?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          AhtiA 1 Reply Last reply
          2
          • VRoninV VRonin

            yes, that's what QPA (qt platform abstraction) does. If you use an OS API directly, however, how can you expect it to magically work?

            AhtiA Offline
            AhtiA Offline
            Ahti
            wrote on last edited by
            #5

            @VRonin simple, just inspect the statement and figure out which Os does the statement belong to and convert the statement to other relevant Os's statements.

            what is a signature ?? Lol

            jsulmJ 1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6
              • isn't there any way to just write code for any api and then it gets converted to a particular Os's api automatically ?

              That would be nearly impossible to create such tool.
              Windows contains thousands API calls and Mac might not have evenly remotely
              the same concepts in its API. And reverse. Mac has features not seen in windows. etc.

              So hence we use a framework as Qt as not to have to write the same code for each platform we want to support.

              Maybe You can tell why you want to use native api calls?
              What does it do for you that you cannot use Qt for?

              1 Reply Last reply
              2
              • AhtiA Ahti

                @VRonin simple, just inspect the statement and figure out which Os does the statement belong to and convert the statement to other relevant Os's statements.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Ahti said in How do i run my app on any OS when the app includes Windows Api ?:

                simple

                Simple? You never developed for several platforms, right? Differences between different platforms and their APIs are huge. Even platforms providing same APIs are not exactly same. For example UNIX with posix: if your application works fine on Linux that does not mean it will work just fine on FreeBSD even if it only uses posix.
                If it would be simple we would have such converter.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                4

                • Login

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