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. Get system information UWP
Forum Updated to NodeBB v4.3 + New Features

Get system information UWP

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 5.8k 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by
    #1

    Hi! I want to develop the Universal Windows Application which will display the system information such as RAM capacity, GPU information, Drives and so on. I used the WMI for Win32 (Desktop) app. From the official UWP documentation I can't use the WMI. So how to get such information? Thanks.

    joeQJ 1 Reply Last reply
    0
    • Cobra91151C Cobra91151

      Hi! I want to develop the Universal Windows Application which will display the system information such as RAM capacity, GPU information, Drives and so on. I used the WMI for Win32 (Desktop) app. From the official UWP documentation I can't use the WMI. So how to get such information? Thanks.

      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      @Cobra91151 Hi, friend. Welcome.

      QSysinfo could give you some help.

      Just do it!

      Cobra91151C 1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        It's not gonna be that easy. UWP is by design a sandbox so you don't get to poke inside the system or other processes too deep, but you might be able to gather some bits and pieces.
        For the filesystem info you can check out the Windows.Devices.Enumeration namespace. Some of it may be covered QFileSystemModel, but I haven't checked.
        For the RAM info you might get some info via Windows.System.MemoryManager.
        For GPU I'd imagine you'd have to go through the DirectX layer, but since Qt uses ANGLE wrapper for UWP you would probably get the ANGLE info, not the gpu under it, unless of course you bypass Qt and go to the DirectX directly.

        Cobra91151C 2 Replies Last reply
        4
        • joeQJ joeQ

          @Cobra91151 Hi, friend. Welcome.

          QSysinfo could give you some help.

          Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #4

          @joeQ

          I know about QSysInfo but there no such information.

          1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            It's not gonna be that easy. UWP is by design a sandbox so you don't get to poke inside the system or other processes too deep, but you might be able to gather some bits and pieces.
            For the filesystem info you can check out the Windows.Devices.Enumeration namespace. Some of it may be covered QFileSystemModel, but I haven't checked.
            For the RAM info you might get some info via Windows.System.MemoryManager.
            For GPU I'd imagine you'd have to go through the DirectX layer, but since Qt uses ANGLE wrapper for UWP you would probably get the ANGLE info, not the gpu under it, unless of course you bypass Qt and go to the DirectX directly.

            Cobra91151C Offline
            Cobra91151C Offline
            Cobra91151
            wrote on last edited by
            #5

            @Chris-Kawa

            I will check it. Thank you.

            1 Reply Last reply
            0
            • Chris KawaC Chris Kawa

              It's not gonna be that easy. UWP is by design a sandbox so you don't get to poke inside the system or other processes too deep, but you might be able to gather some bits and pieces.
              For the filesystem info you can check out the Windows.Devices.Enumeration namespace. Some of it may be covered QFileSystemModel, but I haven't checked.
              For the RAM info you might get some info via Windows.System.MemoryManager.
              For GPU I'd imagine you'd have to go through the DirectX layer, but since Qt uses ANGLE wrapper for UWP you would probably get the ANGLE info, not the gpu under it, unless of course you bypass Qt and go to the DirectX directly.

              Cobra91151C Offline
              Cobra91151C Offline
              Cobra91151
              wrote on last edited by Cobra91151
              #6

              @Chris-Kawa

              Any documentation how to use UWP API with Qt? In Visual Studio I included: using namespace Windows::Devices::Enumeration; and it works. When adding/including namespaces in Qt I get errors.

              For example:

              .h
              #include <windows.devices.enumeration.h>
              
              .cpp
              DeviceAccessInformation deviceInfo;
              

              I get error: C2065: 'DeviceAccessInformation': undeclared identifier

              Thanks.

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #7

                There are couple of ways to access UWP components with C++. Apart from the hacky c++/cx language extensions Microsoft created there's now a nice header-only library wrapper in native C++ called C++/WinRT. The great thing is it's included directly in the Windows SDK now.
                When you create a Visual Studio project it has a preoperty that selects the Windows SDK version and sets up the needed include and lib paths.
                If you're using qmake for your project you need to set up these paths yourself. Since C++/WinRT is a header-only library all you need is the right include path set up. Depending on which version of Windows SDK you're using and your installation path it might look something like this in your .pro file:

                INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0"
                

                After that re-run qmake (in Qt Creator menu Build -> Run qmake) and you can do:

                #include  "winrt/windows.devices.enumeration.h"
                

                For examples on how to use it you can browse through the various samples on the github page of the project.

                Cobra91151C 1 Reply Last reply
                4
                • Chris KawaC Chris Kawa

                  There are couple of ways to access UWP components with C++. Apart from the hacky c++/cx language extensions Microsoft created there's now a nice header-only library wrapper in native C++ called C++/WinRT. The great thing is it's included directly in the Windows SDK now.
                  When you create a Visual Studio project it has a preoperty that selects the Windows SDK version and sets up the needed include and lib paths.
                  If you're using qmake for your project you need to set up these paths yourself. Since C++/WinRT is a header-only library all you need is the right include path set up. Depending on which version of Windows SDK you're using and your installation path it might look something like this in your .pro file:

                  INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0"
                  

                  After that re-run qmake (in Qt Creator menu Build -> Run qmake) and you can do:

                  #include  "winrt/windows.devices.enumeration.h"
                  

                  For examples on how to use it you can browse through the various samples on the github page of the project.

                  Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on last edited by Cobra91151
                  #8

                  @Chris-Kawa

                  I have added the Win SDK path (INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0") to the .pro file and it is the same as your include path. Also added the #include "winrt/windows.devices.enumeration.h" to the header file but it still can't find the DeviceAccessInformation deviceInfo;, throws error: C2065: DeviceAccessInformation: undeclared identifier.

                  Also I have checked the samples, and add the namespace.
                  using namespace winrt;

                  and it displays the error: C2871: 'winrt': a namespace with this name does not exist

                  Also I have noticed the warning: : -1: warning: winrt_manifest_install.path is not defined: install target not created

                  I think the problem is with the wrong includes or I missing something.

                  1 Reply Last reply
                  0
                  • Cobra91151C Offline
                    Cobra91151C Offline
                    Cobra91151
                    wrote on last edited by
                    #9

                    I have included the WindowsApp library but the issue still exists.

                    Code:
                    .pro

                    contains(QMAKE_TARGET.arch, x86_64) {
                        LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.16299.0/um/x64" -lWindowsApp
                    } else {
                        LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.16299.0/um/x86" -lWindowsApp
                    }
                    
                    1 Reply Last reply
                    0
                    • Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by Chris Kawa
                      #10

                      Sorry, it seems I jumped the gun on the info about C++/WinRT being part of Windows SDK already. According to the author it's currently in the preview versions and will be part of the future official releases. I got confused because there's a winrt directory with all the headers in the SDK, but that's for C++/cx. C++/WinRT will be placed in cppwinrt directory.

                      So for now you need to download C++/WinRT separately from https://github.com/Microsoft/cppwinrt.
                      Apparently it's also not entirely header-only so you do need to add windowsapp to the linker.
                      Last thing is that the library uses C++17 so you'll need to enable that in the compiler.

                      So here's an example I got to work that lists all the devices on your pc.
                      In your .pro file add these:

                      INCLUDEPATH += <wherever you downloaded the winrt library from github>
                      QMAKE_CXXFLAGS += /std:c++17
                      LIBS += -lwindowsapp
                      

                      And the main.cpp looks like this:

                      #include <QString>
                      #include <QDebug>
                      #include "winrt/Windows.Devices.Enumeration.h"
                      
                      using namespace winrt;
                      using namespace winrt::Windows::Devices::Enumeration;
                      
                      int main()
                      {
                          init_apartment(); //this initializes com
                      
                          DeviceInformationCollection infos = DeviceInformation::FindAllAsync().get();
                      
                          for (const auto& info : infos)
                              qDebug() << QString::fromWCharArray(info.Name().c_str());
                      }
                      

                      UWP libraries are highly asynchronous so if you'd like to use some of those async features you will also have to add the /await compiler flag to enable coroutine support in the compiler.

                      Cobra91151C 1 Reply Last reply
                      1
                      • Cobra91151C Offline
                        Cobra91151C Offline
                        Cobra91151
                        wrote on last edited by Cobra91151
                        #11

                        @Chris-Kawa
                        What do you mean: INCLUDEPATH += <wherever you downloaded the winrt library from github>? There are only header files (in the .../cppwinrt-master/10.0.16299.0/winrt) directory. I have downloaded it from the link:
                        https://github.com/Microsoft/cppwinrt . Thanks.

                        .pro:

                        QMAKE_CXXFLAGS += /std:c++17
                        INCLUDEPATH += "C:/Users/cobra/Downloads/cppwinrt-master/10.0.16299.0"
                        LIBS += -lwindowsapp
                        

                        .h

                        #include "winrt/windows.devices.enumeration.h"
                        using namespace winrt;
                        using namespace winrt::Windows::Devices::Enumeration;
                        

                        .cpp

                        init_apartment(); //this initializes com
                        DeviceInformationCollection infos = DeviceInformation::FindAllAsync().get();
                        
                         for (const auto &info : infos) {
                                qDebug() << QString::fromWCharArray(info.Name().c_str());
                         }
                        

                        It throws a lot of errors:

                        1_1514413761570_2017-12-28_002852.jpg
                        0_1514413761570_2017-12-28_002833.jpg

                        1 Reply Last reply
                        0
                        • Cobra91151C Offline
                          Cobra91151C Offline
                          Cobra91151
                          wrote on last edited by Cobra91151
                          #12

                          I have checked it and all errors are from cppwinrt directory where the header files located.

                          I think something are overriding the cppwinrt header files or I use the wrong library. But Qt highlights the code so I am on the right direction. Thank you.

                          1 Reply Last reply
                          0
                          • Chris KawaC Chris Kawa

                            Sorry, it seems I jumped the gun on the info about C++/WinRT being part of Windows SDK already. According to the author it's currently in the preview versions and will be part of the future official releases. I got confused because there's a winrt directory with all the headers in the SDK, but that's for C++/cx. C++/WinRT will be placed in cppwinrt directory.

                            So for now you need to download C++/WinRT separately from https://github.com/Microsoft/cppwinrt.
                            Apparently it's also not entirely header-only so you do need to add windowsapp to the linker.
                            Last thing is that the library uses C++17 so you'll need to enable that in the compiler.

                            So here's an example I got to work that lists all the devices on your pc.
                            In your .pro file add these:

                            INCLUDEPATH += <wherever you downloaded the winrt library from github>
                            QMAKE_CXXFLAGS += /std:c++17
                            LIBS += -lwindowsapp
                            

                            And the main.cpp looks like this:

                            #include <QString>
                            #include <QDebug>
                            #include "winrt/Windows.Devices.Enumeration.h"
                            
                            using namespace winrt;
                            using namespace winrt::Windows::Devices::Enumeration;
                            
                            int main()
                            {
                                init_apartment(); //this initializes com
                            
                                DeviceInformationCollection infos = DeviceInformation::FindAllAsync().get();
                            
                                for (const auto& info : infos)
                                    qDebug() << QString::fromWCharArray(info.Name().c_str());
                            }
                            

                            UWP libraries are highly asynchronous so if you'd like to use some of those async features you will also have to add the /await compiler flag to enable coroutine support in the compiler.

                            Cobra91151C Offline
                            Cobra91151C Offline
                            Cobra91151
                            wrote on last edited by
                            #13

                            @Chris-Kawa

                            I have found why these errors occurs. The problem is with the Qt Kits. I have 3 Qt UWP kits installed:

                            1. Qt 5.9.3 for UWP x32
                            2. Qt 5.9.3 for UWP x64
                            3. Qt 5.9.3 for UWP armv7

                            So when I'm trying to build for x32 or x64 UWP binaries, it throws the errors. But when I set armv7 kit as build target then no errors found and build succeeds. So the question is how to target x32/x64 UWP? Thanks.

                            1 Reply Last reply
                            0
                            • Cobra91151C Offline
                              Cobra91151C Offline
                              Cobra91151
                              wrote on last edited by Cobra91151
                              #14

                              Can anyone confirm that Qt 5.9.3 UWP x32/x64 kits work with UWP API? Thanks in advance.

                              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