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 ?
Forum Updated to NodeBB v4.3 + New Features

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.5k 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.
  • A Offline
    A Offline
    Ahti
    wrote on 26 Oct 2016, 13:49 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Oct 2016, 13:53 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.

      A 1 Reply Last reply 26 Oct 2016, 16:37
      1
      • M mrjj
        26 Oct 2016, 13:53

        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.

        A Offline
        A Offline
        Ahti
        wrote on 26 Oct 2016, 16:37 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
        • V Offline
          V Offline
          VRonin
          wrote on 26 Oct 2016, 17:29 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

          A 1 Reply Last reply 26 Oct 2016, 17:49
          2
          • V VRonin
            26 Oct 2016, 17:29

            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?

            A Offline
            A Offline
            Ahti
            wrote on 26 Oct 2016, 17:49 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

            J 1 Reply Last reply 27 Oct 2016, 04:36
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 26 Oct 2016, 18:15 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
              • A Ahti
                26 Oct 2016, 17:49

                @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.

                J Online
                J Online
                jsulm
                Lifetime Qt Champion
                wrote on 27 Oct 2016, 04:36 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

                1/7

                26 Oct 2016, 13:49

                • Login

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