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. [SOLVED]Finding out CPU architecture programmatically using Qt?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Finding out CPU architecture programmatically using Qt?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.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.
  • N Offline
    N Offline
    nikCoder
    wrote on last edited by
    #1

    Hi !
    Is there a way to find out CPU architecture (e.g ARM / x86) using Qt ?

    Thanks!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Take a look at "Q_PROCESSOR_*":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#Q_PROCESSOR_X86

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcortesi
        wrote on last edited by
        #3

        Class QSysInfo is what you need.
        Note this can be tricky since not all members are defined in all platforms (a design error I think; they should return some kind of null value for all cases). In Python I used it this way:
        @
        from PyQt4.QtCore import QSysInfo
        try:
        junk = QSysInfo.WindowsVersion
        self.osType = 'Win'
        except: # that static var does not exist, so,
        try:
        junk = QSysInfo.MacintoshVersion
        self.osType = 'Mac'
        except: # that doesn't exist either, ergo:
        self.osType = 'Linux'

        @

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nikCoder
          wrote on last edited by
          #4

          Thanks for the replies.
          Are the Q_PROCESSOR_* macros available in Qt 4.8? I didn't find it in Qt docs for 4.8 ?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            I'm actually afraid they aren't, but you should be able to simply add "qcompilerdetection.h":http://qt.gitorious.org/qt/qtbase/blobs/stable/src/corelib/global/qprocessordetection.h to your project, which will set Q_PROCESSOR_* (or just pick the required definitions from there).

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nikCoder
              wrote on last edited by
              #6

              Thanks Lukas! I will try doing that.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nikCoder
                wrote on last edited by
                #7

                This worked for me:

                @#if defined(arm) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)
                //code for target
                #endif@

                Please mark the post as solved .

                cheers,
                Nik

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  [quote author="nikCoder" date="1359704859"]Please mark the post as solved.[/quote]

                  You can do so by editing your initial post and change the title to '[Solved] ...'. There is unfortunetly no automatism for this yet.

                  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