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. Core Temp Shared Memory in Qt C++ - Windows
Forum Updated to NodeBB v4.3 + New Features

Core Temp Shared Memory in Qt C++ - Windows

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 4 Posters 4.2k Views 2 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.
  • R Offline
    R Offline
    Ryan R
    wrote on last edited by Ryan R
    #1

    Solved, I released the working code and quick instructions as a reply at the bottom of the thread.

    Hey guys,

    I am currently developing a status monitor for my gaming PC using C++/XML with Qt Creator. I would like to integrate the Core Temp Shared Memory features to grab CPU temperature in real-time.

    https://www.alcpu.com/forums/viewtopic.php?t=649

    That tutorial explains how to setup the libraries for MSVS, but not for Qt. Could someone explain how to import and use this library in the latest version of Qt Creator?

    Apparently the only file you need is the DLL; I've tried importing this via the Qt Creator Wizard, and by following that tutorial. However, I get the following error: "undefined reference to 'fnGetCoreTempInfoAlt'".

    I have got this to work with LabVIEW, so I know that the libraries work correctly, but I've had no luck with Qt.

    Here is my current project:

    project.pro

    QT += core gui network
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    LIBS += C:\WinTempTest32\GetCoreTempInfo.lib
    
    HEADERS += \
        mainwindow.h
    
    FORMS += \
        mainwindow.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    DISTFILES +=
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QDebug>
    #include <QHostInfo>
    #include <QMenuBar>
    
    #include <windows.h> // see note 1
    #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
    #pragma pack (push, 4) // see note 3
    
    // see note 4
    struct CORE_TEMP_SHARED_DATA {
        DWORD       uiLoad[256];    // one per core
        DWORD       uiTjMax[128];   // one per cpu
        DWORD       uiCoreCnt;
        DWORD       uiCPUCnt;
        FLOAT       fTemp[256];     // one per core
        FLOAT       fVID;
        FLOAT       fCPUSpeed;
        FLOAT       fFSBSpeed;
        FLOAT       fMultipier;
        CHAR        sCPUName[100];
        BYTE        ucFahrenheit;
        BYTE        ucDeltaToTjMax;
    };
    
    // see note 5
    extern "C" bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);
    
    #pragma pack (pop)
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private slots:
        void on_pushButton_clicked();
    
    
    private:
        Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H
    
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        setStyleSheet("background:transparent;");
        setAttribute(Qt::WA_TranslucentBackground);
        setWindowFlags(Qt::FramelessWindowHint); // activate for border removal
    
        QMenuBar *menuBar = new QMenuBar(0);
    
        ui->labelHostname->setText(QHostInfo::localHostName());
    
        CORE_TEMP_SHARED_DATA ct;
    
        if (fnGetCoreTempInfoAlt(&ct)) {
          // process ct
        } else {
          // GetLastError() contains error code
        }
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        qDebug("Exiting Program...");
        QCoreApplication::quit();
    }
    
    

    Any help would be greatly appriciated.

    Thanks,
    Ryan

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

      Hi,

      Might be a silly question but are you sure your import library is of the right architecture ?

      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
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        Looks to me like a simple C library that ships with includes (actualy just 1, GetCoreTempInfo.h) and a .lib file for your linker so you should be able to import it directly using the "add external library" tool of Qt Creator

        "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

        1 Reply Last reply
        3
        • R Offline
          R Offline
          Ryan R
          wrote on last edited by
          #4

          Thanks for the replies, guys!

          I've just tried with MinGW and MSVC 32 and 64 bit version compilers and libraries, but I just get the same error. I've also tried right clicking the project and adding the library, but I just get the undefined reference to 'fnGetCoreTempInfoAlt@4'. Adding the library with the wizard produces the following in the .pro file:

          win32: LIBS += -L$$PWD/../../../../../../CoreTempLib/x86/ -lGetCoreTempInfo
          
          INCLUDEPATH += $$PWD/../../../../../../CoreTempLib/x86
          DEPENDPATH += $$PWD/../../../../../../CoreTempLib/x86
          

          With the following compile output:

          20:12:45: Running steps for project QtCoreTempTest...
          20:12:45: Configuration unchanged, skipping qmake step.
          20:12:45: Starting: "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j8
          E:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
          mingw32-make[1]: Entering directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
          g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\QtCoreTempTest\main.cpp
          g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\QtCoreTempTest\mainwindow.cpp
          E:\Qt\5.14.2\mingw73_32\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/debug/moc_predefs.h" -IE:/Qt/5.14.2/mingw73_32/mkspecs/win32-g++ -I"C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/QtCoreTempTest" -IC:/CoreTempLib/x86 -IE:/Qt/5.14.2/mingw73_32/include -IE:/Qt/5.14.2/mingw73_32/include/QtWidgets -IE:/Qt/5.14.2/mingw73_32/include/QtGui -IE:/Qt/5.14.2/mingw73_32/include/QtANGLE -IE:/Qt/5.14.2/mingw73_32/include/QtCore -I. -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed -IE:/Qt/Tools/mingw730_32/i686-w64-mingw32/include ..\QtCoreTempTest\mainwindow.h -o debug\moc_mainwindow.cpp
          g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
          In file included from ..\QtCoreTempTest\main.cpp:1:0:
          ..\QtCoreTempTest\mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
           #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
           
          In file included from ..\QtCoreTempTest\mainwindow.cpp:1:0:
          ..\QtCoreTempTest\mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
           #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
           
          In file included from debug\moc_mainwindow.cpp:10:0:
          debug\../../QtCoreTempTest/mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
           #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
           
          g++ -Wl,-subsystem,windows -mthreads -o debug\QtCoreTempTest.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  -LC:\CoreTempLib\x86 -lGetCoreTempInfo E:\Qt\5.14.2\mingw73_32\lib\libQt5Widgets.a E:\Qt\5.14.2\mingw73_32\lib\libQt5Gui.a E:\Qt\5.14.2\mingw73_32\lib\libQt5Core.a  -lmingw32 E:\Qt\5.14.2\mingw73_32\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 
          debug/mainwindow.o: In function `ZN10MainWindowC2EP7QWidget':
          C:\Users\ariie\Desktop\Qt Programming\QtCoreTempTest\build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/../QtCoreTempTest/mainwindow.cpp:12: undefined reference to `fnGetCoreTempInfoAlt@4'
          collect2.exe: error: ld returned 1 exit status
          mingw32-make[1]: *** [Makefile.Debug:72: debug/QtCoreTempTest.exe] Error 1
          mingw32-make: *** [Makefile:45: debug] Error 2
          mingw32-make[1]: Leaving directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
          20:12:51: The process "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
          Error while building/deploying project QtCoreTempTest (kit: Desktop Qt 5.14.2 MinGW 32-bit)
          When executing step "Make"
          20:12:51: Elapsed time: 00:06.
          

          One thing I don't understand is what the header file is for. It is a loose file in the shared memory folder (GetCoreTempinfo.h); this file is not being imported since it isn't in the x64 or x86 folders where the libraries are. Do I have to import this seperately, or is it for something else?

          Thanks,
          Ryan

          VRoninV 1 Reply Last reply
          0
          • R Ryan R

            Thanks for the replies, guys!

            I've just tried with MinGW and MSVC 32 and 64 bit version compilers and libraries, but I just get the same error. I've also tried right clicking the project and adding the library, but I just get the undefined reference to 'fnGetCoreTempInfoAlt@4'. Adding the library with the wizard produces the following in the .pro file:

            win32: LIBS += -L$$PWD/../../../../../../CoreTempLib/x86/ -lGetCoreTempInfo
            
            INCLUDEPATH += $$PWD/../../../../../../CoreTempLib/x86
            DEPENDPATH += $$PWD/../../../../../../CoreTempLib/x86
            

            With the following compile output:

            20:12:45: Running steps for project QtCoreTempTest...
            20:12:45: Configuration unchanged, skipping qmake step.
            20:12:45: Starting: "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j8
            E:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
            mingw32-make[1]: Entering directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
            g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\QtCoreTempTest\main.cpp
            g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\QtCoreTempTest\mainwindow.cpp
            E:\Qt\5.14.2\mingw73_32\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/debug/moc_predefs.h" -IE:/Qt/5.14.2/mingw73_32/mkspecs/win32-g++ -I"C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/QtCoreTempTest" -IC:/CoreTempLib/x86 -IE:/Qt/5.14.2/mingw73_32/include -IE:/Qt/5.14.2/mingw73_32/include/QtWidgets -IE:/Qt/5.14.2/mingw73_32/include/QtGui -IE:/Qt/5.14.2/mingw73_32/include/QtANGLE -IE:/Qt/5.14.2/mingw73_32/include/QtCore -I. -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed -IE:/Qt/Tools/mingw730_32/i686-w64-mingw32/include ..\QtCoreTempTest\mainwindow.h -o debug\moc_mainwindow.cpp
            g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\QtCoreTempTest -I. -IC:\CoreTempLib\x86 -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
            In file included from ..\QtCoreTempTest\main.cpp:1:0:
            ..\QtCoreTempTest\mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
             #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
             
            In file included from ..\QtCoreTempTest\mainwindow.cpp:1:0:
            ..\QtCoreTempTest\mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
             #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
             
            In file included from debug\moc_mainwindow.cpp:10:0:
            debug\../../QtCoreTempTest/mainwindow.h:7:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
             #pragma comment (lib, "GetCoreTempInfo.lib") // see note 2
             
            g++ -Wl,-subsystem,windows -mthreads -o debug\QtCoreTempTest.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  -LC:\CoreTempLib\x86 -lGetCoreTempInfo E:\Qt\5.14.2\mingw73_32\lib\libQt5Widgets.a E:\Qt\5.14.2\mingw73_32\lib\libQt5Gui.a E:\Qt\5.14.2\mingw73_32\lib\libQt5Core.a  -lmingw32 E:\Qt\5.14.2\mingw73_32\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 
            debug/mainwindow.o: In function `ZN10MainWindowC2EP7QWidget':
            C:\Users\ariie\Desktop\Qt Programming\QtCoreTempTest\build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/../QtCoreTempTest/mainwindow.cpp:12: undefined reference to `fnGetCoreTempInfoAlt@4'
            collect2.exe: error: ld returned 1 exit status
            mingw32-make[1]: *** [Makefile.Debug:72: debug/QtCoreTempTest.exe] Error 1
            mingw32-make: *** [Makefile:45: debug] Error 2
            mingw32-make[1]: Leaving directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
            20:12:51: The process "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
            Error while building/deploying project QtCoreTempTest (kit: Desktop Qt 5.14.2 MinGW 32-bit)
            When executing step "Make"
            20:12:51: Elapsed time: 00:06.
            

            One thing I don't understand is what the header file is for. It is a loose file in the shared memory folder (GetCoreTempinfo.h); this file is not being imported since it isn't in the x64 or x86 folders where the libraries are. Do I have to import this seperately, or is it for something else?

            Thanks,
            Ryan

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Ryan-R said in Core Temp Shared Memory in Qt C++ - Windows:

            #pragma comment

            What are you using those pragma for? If you are following the tutorial you posted above don't, they are overengeneering the whole thing. Disregard what they say.

            what the header file is for

            You know when you type #include <QObject>? that tells the compiler that you are using stuff that is defined inside a file named QObject that is located in one of the folders specifyed by INCLUDEPATH.
            What you need to do is remove /x86 from INCLUDEPATH += $$PWD/../../../../../../CoreTempLib/x86 and then put #include <GetCoreTempinfo.h> at the top of the source file

            "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

            1 Reply Last reply
            4
            • R Offline
              R Offline
              Ryan R
              wrote on last edited by
              #6

              @VRonin That's got it, thanks! I removed all of the code from the previous tutorial, added the library with the include path to CoreTempLib and added the header file declaration.

              (I think) I'm able to access variables in the shared memory! The current problem is the data conversion; I'm trying to convert all of the values to QStrings so I can use it on the GUI. This is the shared memory structure from the documentation:

              	DWORD       uiLoad[256];    // one per core
              	DWORD       uiTjMax[128];   // one per cpu
              	DWORD       uiCoreCnt;
              	DWORD       uiCPUCnt;
              	FLOAT       fTemp[256];     // one per core
              	FLOAT       fVID;
              	FLOAT       fCPUSpeed;
              	FLOAT       fFSBSpeed;
              	FLOAT       fMultipier;	
              	CHAR        sCPUName[100];
              	BYTE        ucFahrenheit;
              	BYTE        ucDeltaToTjMax;
              

              But when I try to convert "ct.fTemp[0]" from float to QString, I get outputs such as;

              "1.18057e-38" from "qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[0]);".
              "0.000000" from "printf("\nTest2: %f", ct.fTemp[1]);"
              

              So either I'm not converting the data properly or the library is returning incorrect data. Does anyone know an alternate way for converting this data?

              One thing I noticed is that in the documentation, there is a note for the variables:

              unsigned int is a 32bit unsigned integer.
              unsigned char is an 8bit (1 byte) value.
              float is a 32bit floating point value.
              

              So are there any alternate method for converting 32-bit floats to QStrings, or am I missing something completely?

              Any help is greatly appriciated, and will also upload the finished code if I get it working!

              Thanks,
              Ryan

              VRoninV 1 Reply Last reply
              0
              • R Ryan R

                @VRonin That's got it, thanks! I removed all of the code from the previous tutorial, added the library with the include path to CoreTempLib and added the header file declaration.

                (I think) I'm able to access variables in the shared memory! The current problem is the data conversion; I'm trying to convert all of the values to QStrings so I can use it on the GUI. This is the shared memory structure from the documentation:

                	DWORD       uiLoad[256];    // one per core
                	DWORD       uiTjMax[128];   // one per cpu
                	DWORD       uiCoreCnt;
                	DWORD       uiCPUCnt;
                	FLOAT       fTemp[256];     // one per core
                	FLOAT       fVID;
                	FLOAT       fCPUSpeed;
                	FLOAT       fFSBSpeed;
                	FLOAT       fMultipier;	
                	CHAR        sCPUName[100];
                	BYTE        ucFahrenheit;
                	BYTE        ucDeltaToTjMax;
                

                But when I try to convert "ct.fTemp[0]" from float to QString, I get outputs such as;

                "1.18057e-38" from "qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[0]);".
                "0.000000" from "printf("\nTest2: %f", ct.fTemp[1]);"
                

                So either I'm not converting the data properly or the library is returning incorrect data. Does anyone know an alternate way for converting this data?

                One thing I noticed is that in the documentation, there is a note for the variables:

                unsigned int is a 32bit unsigned integer.
                unsigned char is an 8bit (1 byte) value.
                float is a 32bit floating point value.
                

                So are there any alternate method for converting 32-bit floats to QStrings, or am I missing something completely?

                Any help is greatly appriciated, and will also upload the finished code if I get it working!

                Thanks,
                Ryan

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                @Ryan-R said in Core Temp Shared Memory in Qt C++ - Windows:

                unsigned char is an 8bit (1 byte) value.

                This is guaranteed by the C++ standard

                unsigned int is a 32bit unsigned integer.

                This is also a requirement of Qt

                float is a 32bit floating point value

                This depends on the compiler but in 99% of the cases it's true (you can check with 8*sizeof(float)).

                "ct.fTemp[0]" from float to QString

                how are you accomplishing it?

                "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

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  Ryan R
                  wrote on last edited by Ryan R
                  #8

                  I'm literally just using "qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[1]);" at the moment to get output, then the idea is I'd just store it in a QString, then setText on a label GUI object.

                   CORE_TEMP_SHARED_DATA ct;
                   qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[1]);
                  
                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by VRonin
                    #9

                    That's just because ct is uninitialised you need to call the function that fills it with data.

                    CoreTempSharedDataEx ct;
                    fnGetCoreTempInfo(&ct);
                    qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[1]);
                    

                    P.S.
                    I see you are still using CORE_TEMP_SHARED_DATA. As mentioned you should get rid of everyting in your program that comes from the "tutorial" link you psted above

                    "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

                    1 Reply Last reply
                    3
                    • R Offline
                      R Offline
                      Ryan R
                      wrote on last edited by
                      #10

                      Thanks for the help! That makes sense now; before it was just creating the structure without any data.

                      I replaced "CORE_TEMP_SHARED_DATA ct;" with "CoreTempSharedDataEx ct;", but it's apparently an unknown type name. However, "fnGetCoreTempInfo(&ct)" seems to be recongised at least.

                      The compiler output for CoreTempSharedDataEx is below; it keeps suggesting I use core_temp_shared_data. But if I do, "fnGetCoreTempInfo(&ct);" is no longer recognised.

                      17:33:41: Running steps for project QtCoreTempTest...
                      17:33:41: Configuration unchanged, skipping qmake step.
                      17:33:41: Starting: "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j8
                      E:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
                      mingw32-make[1]: Entering directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:12:5: error: 'CoreTempSharedDataEx' was not declared in this scope
                           CoreTempSharedDataEx ct;
                           ^~~~~~~~~~~~~~~~~~~~
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:12:5: note: suggested alternative: 'core_temp_shared_data'
                           CoreTempSharedDataEx ct;
                           ^~~~~~~~~~~~~~~~~~~~
                           core_temp_shared_data
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:13:23: error: cannot bind non-const lvalue reference of type 'CORE_TEMP_SHARED_DATA*& {aka core_temp_shared_data*&}' to an rvalue of type 'CORE_TEMP_SHARED_DATA* {aka core_temp_shared_data*}'
                           fnGetCoreTempInfo(&ct);
                                             ^~~
                      In file included from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.h:7:0,
                                       from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:1:
                      C:\CoreTempLib/GetCoreTempinfo.h:27:26: note:   initializing argument 1 of 'bool fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA*&)'
                       bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
                                                ^~~~~~~~~~~~~~~~~
                      mingw32-make[1]: *** [Makefile.Debug:472: debug/mainwindow.o] Error 1
                      mingw32-make[1]: Leaving directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                      mingw32-make: *** [Makefile:45: debug] Error 2
                      17:33:45: The process "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
                      Error while building/deploying project QtCoreTempTest (kit: Desktop Qt 5.14.2 MinGW 32-bit)
                      When executing step "Make"
                      17:33:45: Elapsed time: 00:05.
                      

                      However, if I use "CORE_TEMP_SHARED_DATA ct;" with "fnGetCoreTempInfo(&ct);", I get the following:

                      17:48:36: Running steps for project QtCoreTempTest...
                      17:48:36: Configuration unchanged, skipping qmake step.
                      17:48:36: Starting: "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j8
                      E:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
                      mingw32-make[1]: Entering directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\main.cpp
                      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp
                      E:\Qt\5.14.2\mingw73_32\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/debug/moc_predefs.h" -IE:/Qt/5.14.2/mingw73_32/mkspecs/win32-g++ -IC:/Users/ariie/Desktop/QtProgramming/QtCoreTempTest/QtCoreTempTest -IC:/CoreTempLib -IE:/Qt/5.14.2/mingw73_32/include -IE:/Qt/5.14.2/mingw73_32/include/QtWidgets -IE:/Qt/5.14.2/mingw73_32/include/QtGui -IE:/Qt/5.14.2/mingw73_32/include/QtANGLE -IE:/Qt/5.14.2/mingw73_32/include/QtCore -I. -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed -IE:/Qt/Tools/mingw730_32/i686-w64-mingw32/include ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.h -o debug\moc_mainwindow.cpp
                      g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
                      ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:12:23: error: cannot bind non-const lvalue reference of type 'CORE_TEMP_SHARED_DATA*& {aka core_temp_shared_data*&}' to an rvalue of type 'CORE_TEMP_SHARED_DATA* {aka core_temp_shared_data*}'
                           fnGetCoreTempInfo(&ct);
                                             ^~~
                      In file included from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.h:7:0,
                                       from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:1:
                      C:\CoreTempLib/GetCoreTempinfo.h:27:26: note:   initializing argument 1 of 'bool fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA*&)'
                       bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
                                                ^~~~~~~~~~~~~~~~~
                      mingw32-make[1]: *** [Makefile.Debug:472: debug/mainwindow.o] Error 1
                      mingw32-make[1]: *** Waiting for unfinished jobs....
                      mingw32-make[1]: Leaving directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                      mingw32-make: *** [Makefile:45: debug] Error 2
                      17:48:42: The process "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
                      Error while building/deploying project QtCoreTempTest (kit: Desktop Qt 5.14.2 MinGW 32-bit)
                      When executing step "Make"
                      17:48:42: Elapsed time: 00:06.
                      

                      Any ideas? This is the first time I've used external DLLs with Qt C++; I usually code in C on Linux, where all you have to do is add the "-llibrary" parameter on the end of the complication command!

                      Thanks,
                      Ryan

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

                        can you post the contents of GetCoreTempinfo.h?

                        "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

                        1 Reply Last reply
                        1
                        • R Offline
                          R Offline
                          Ryan R
                          wrote on last edited by
                          #12

                          Here's the imported "GetCoreTempinfo.h".

                          Qt does display errors for this header file, now that I've opened it; ranging from unknown type names for UINT and DWORD variables, as well as a few semantic issues. Could the library be incompatible with Qt?

                          #pragma once
                          
                          #ifdef GETCORETEMPINFO_EXPORTS
                          #define GETCORETEMPINFO_API __declspec(dllexport)
                          #else
                          #define GETCORETEMPINFO_API __declspec(dllimport)
                          #endif
                          
                          #define UNKNOWN_EXCEPTION 0x20000000
                          
                          typedef struct core_temp_shared_data
                          {
                          	unsigned int	uiLoad[256];
                          	unsigned int	uiTjMax[128];
                          	unsigned int	uiCoreCnt;
                          	unsigned int	uiCPUCnt;
                          	float			fTemp[256];
                          	float			fVID;
                          	float			fCPUSpeed;
                          	float			fFSBSpeed;
                          	float			fMultipier;	
                          	char			sCPUName[100];
                          	unsigned char	ucFahrenheit;
                          	unsigned char	ucDeltaToTjMax;
                          }CORE_TEMP_SHARED_DATA,*PCORE_TEMP_SHARED_DATA,**PPCORE_TEMP_SHARED_DATA;
                          
                          bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
                          bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);
                          
                          class GETCORETEMPINFO_API CoreTempProxy
                          {
                          public:
                          	CoreTempProxy(void);
                          	virtual ~CoreTempProxy(void);
                          	
                          	UINT GetCoreLoad(int Index) const;
                              UINT GetTjMax(int Index) const;
                              UINT GetCoreCount() const;
                              UINT GetCPUCount() const;
                              float GetTemp(int Index) const;
                              float GetVID() const;
                              float GetCPUSpeed() const;
                              float GetFSBSpeed() const;
                              float GetMultiplier() const;
                              LPCSTR GetCPUName() const;
                              bool IsFahrenheit() const;
                              bool IsDistanceToTjMax() const;
                              const CORE_TEMP_SHARED_DATA &GetDataStruct() const;
                          
                          	bool GetData();
                          	DWORD GetDllError() const { return GetLastError(); }
                          	LPCWSTR GetErrorMessage();
                          private:
                          
                          	CORE_TEMP_SHARED_DATA m_pCoreTempData;
                          	WCHAR m_ErrorMessage[100];
                          };
                          
                          

                          Thanks for the quick replies!
                          Ryan

                          JonBJ 1 Reply Last reply
                          0
                          • R Ryan R

                            Here's the imported "GetCoreTempinfo.h".

                            Qt does display errors for this header file, now that I've opened it; ranging from unknown type names for UINT and DWORD variables, as well as a few semantic issues. Could the library be incompatible with Qt?

                            #pragma once
                            
                            #ifdef GETCORETEMPINFO_EXPORTS
                            #define GETCORETEMPINFO_API __declspec(dllexport)
                            #else
                            #define GETCORETEMPINFO_API __declspec(dllimport)
                            #endif
                            
                            #define UNKNOWN_EXCEPTION 0x20000000
                            
                            typedef struct core_temp_shared_data
                            {
                            	unsigned int	uiLoad[256];
                            	unsigned int	uiTjMax[128];
                            	unsigned int	uiCoreCnt;
                            	unsigned int	uiCPUCnt;
                            	float			fTemp[256];
                            	float			fVID;
                            	float			fCPUSpeed;
                            	float			fFSBSpeed;
                            	float			fMultipier;	
                            	char			sCPUName[100];
                            	unsigned char	ucFahrenheit;
                            	unsigned char	ucDeltaToTjMax;
                            }CORE_TEMP_SHARED_DATA,*PCORE_TEMP_SHARED_DATA,**PPCORE_TEMP_SHARED_DATA;
                            
                            bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
                            bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);
                            
                            class GETCORETEMPINFO_API CoreTempProxy
                            {
                            public:
                            	CoreTempProxy(void);
                            	virtual ~CoreTempProxy(void);
                            	
                            	UINT GetCoreLoad(int Index) const;
                                UINT GetTjMax(int Index) const;
                                UINT GetCoreCount() const;
                                UINT GetCPUCount() const;
                                float GetTemp(int Index) const;
                                float GetVID() const;
                                float GetCPUSpeed() const;
                                float GetFSBSpeed() const;
                                float GetMultiplier() const;
                                LPCSTR GetCPUName() const;
                                bool IsFahrenheit() const;
                                bool IsDistanceToTjMax() const;
                                const CORE_TEMP_SHARED_DATA &GetDataStruct() const;
                            
                            	bool GetData();
                            	DWORD GetDllError() const { return GetLastError(); }
                            	LPCWSTR GetErrorMessage();
                            private:
                            
                            	CORE_TEMP_SHARED_DATA m_pCoreTempData;
                            	WCHAR m_ErrorMessage[100];
                            };
                            
                            

                            Thanks for the quick replies!
                            Ryan

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #13

                            @Ryan-R said in Core Temp Shared Memory in Qt C++ - Windows:

                            Qt does display errors for this header file, now that I've opened it; ranging from unknown type names for UINT and DWORD variables,

                            This is a Windows-specific header file. You will need to include something like #include <windows.h> before this header file for it to be acceptable, since it does not do so itself.

                            R 1 Reply Last reply
                            2
                            • JonBJ JonB

                              @Ryan-R said in Core Temp Shared Memory in Qt C++ - Windows:

                              Qt does display errors for this header file, now that I've opened it; ranging from unknown type names for UINT and DWORD variables,

                              This is a Windows-specific header file. You will need to include something like #include <windows.h> before this header file for it to be acceptable, since it does not do so itself.

                              R Offline
                              R Offline
                              Ryan R
                              wrote on last edited by
                              #14

                              @JonB I've got "#include <windows.h>" inside "mainwindow.h", so shouldn't it be recognised?

                              #include <QMainWindow>
                              #include <windows.h> // see note 1
                              #include <GetCoreTempinfo.h>
                              #include <QDebug>
                              #include <QString>
                              

                              I do get a warning about "#include <GetCoreTempinfo.h>"; "non-portable path to file ' <GetCoreTempinfo.h>'; specified path differs in case from file name on disk.

                              Thanks,
                              Ryan

                              JonBJ 1 Reply Last reply
                              0
                              • R Ryan R

                                @JonB I've got "#include <windows.h>" inside "mainwindow.h", so shouldn't it be recognised?

                                #include <QMainWindow>
                                #include <windows.h> // see note 1
                                #include <GetCoreTempinfo.h>
                                #include <QDebug>
                                #include <QString>
                                

                                I do get a warning about "#include <GetCoreTempinfo.h>"; "non-portable path to file ' <GetCoreTempinfo.h>'; specified path differs in case from file name on disk.

                                Thanks,
                                Ryan

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by JonB
                                #15

                                @Ryan-R
                                So that would look like it makes it OK to compile when included via mainwindow.h, which is fine. But when you ask Creator to read in GetCoreTempinfo.h to view on its own, it might give warnings without windows.h. That's OK, so long as it compiles.

                                "#include <GetCoreTempinfo.h>"; "non-portable path to file ' <GetCoreTempinfo.h>'; specified path differs in case from file name on disk.

                                You include GetCoreTempinfo.h. I imagine you have saved/copied this file onto disk with e.g. all lower case letters. You will be OK under Windows; you might like to rename the file to match the way it is spelt here anyway, but not vital.

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

                                  I see, the header file doesn't match the documentation on the website, typical :)

                                  So it should be something like this:

                                  #include <windows.h>
                                  #include <GetCoreTempinfo.h>
                                  
                                  // other stuff in your program
                                  
                                  CORE_TEMP_SHARED_DATA ct;
                                  fnGetCoreTempInfo(&ct);
                                  qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[1]);
                                  

                                  "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

                                  1 Reply Last reply
                                  1
                                  • R Offline
                                    R Offline
                                    Ryan R
                                    wrote on last edited by
                                    #17

                                    @VRonin The Core Temp side seems to be poorly documentated in general!

                                    The only issue with using "fnGetCoreTempInfo(&ct);" is the following errror.

                                    ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:12:23: error: cannot bind non-const lvalue reference of type 'CORE_TEMP_SHARED_DATA*& {aka core_temp_shared_data*&}' to an rvalue of type 'CORE_TEMP_SHARED_DATA* {aka core_temp_shared_data*}'
                                    

                                    It seems that one reference is a *&, and the other is just *; with the following compiler output.

                                    12:32:46: Running steps for project QtCoreTempTest...
                                    12:32:46: Configuration unchanged, skipping qmake step.
                                    12:32:46: Starting: "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" -j8
                                    E:/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Debug
                                    mingw32-make[1]: Entering directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                                    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\main.o ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\main.cpp
                                    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp
                                    E:\Qt\5.14.2\mingw73_32\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug/debug/moc_predefs.h" -IE:/Qt/5.14.2/mingw73_32/mkspecs/win32-g++ -IC:/Users/ariie/Desktop/QtProgramming/QtCoreTempTest/QtCoreTempTest -IC:/CoreTempLib -IE:/Qt/5.14.2/mingw73_32/include -IE:/Qt/5.14.2/mingw73_32/include/QtWidgets -IE:/Qt/5.14.2/mingw73_32/include/QtGui -IE:/Qt/5.14.2/mingw73_32/include/QtANGLE -IE:/Qt/5.14.2/mingw73_32/include/QtCore -I. -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include -IE:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed -IE:/Qt/Tools/mingw730_32/i686-w64-mingw32/include ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.h -o debug\moc_mainwindow.cpp
                                    g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest -I. -IC:\CoreTempLib -IE:\Qt\5.14.2\mingw73_32\include -IE:\Qt\5.14.2\mingw73_32\include\QtWidgets -IE:\Qt\5.14.2\mingw73_32\include\QtGui -IE:\Qt\5.14.2\mingw73_32\include\QtANGLE -IE:\Qt\5.14.2\mingw73_32\include\QtCore -Idebug -I. -IE:\Qt\5.14.2\mingw73_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
                                    ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
                                    ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:12:23: error: cannot bind non-const lvalue reference of type 'CORE_TEMP_SHARED_DATA*& {aka core_temp_shared_data*&}' to an rvalue of type 'CORE_TEMP_SHARED_DATA* {aka core_temp_shared_data*}'
                                         fnGetCoreTempInfo(&ct);
                                                           ^~~
                                    In file included from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.h:7:0,
                                                     from ..\..\..\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:1:
                                    C:\CoreTempLib/GetCoreTempInfo.h:27:26: note:   initializing argument 1 of 'bool fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA*&)'
                                     bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
                                                              ^~~~~~~~~~~~~~~~~
                                    mingw32-make[1]: *** [Makefile.Debug:472: debug/mainwindow.o] Error 1
                                    mingw32-make[1]: *** Waiting for unfinished jobs....
                                    mingw32-make[1]: Leaving directory 'C:/Users/ariie/Desktop/Qt Programming/QtCoreTempTest/build-QtCoreTempTest-Desktop_Qt_5_14_2_MinGW_32_bit-Debug'
                                    mingw32-make: *** [Makefile:45: debug] Error 2
                                    12:32:52: The process "E:\Qt\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
                                    Error while building/deploying project QtCoreTempTest (kit: Desktop Qt 5.14.2 MinGW 32-bit)
                                    When executing step "Make"
                                    12:32:52: Elapsed time: 00:06.
                                    

                                    Thanks,
                                    Ryan

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

                                      And this is why I don't like programming in C.

                                      CORE_TEMP_SHARED_DATA ct;
                                      CORE_TEMP_SHARED_DATA* pct=&ct;
                                      fnGetCoreTempInfo(pct);
                                      qDebug() << "\n\n\nTest: " << QString::number(ct.fTemp[1]);
                                      

                                      "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

                                      1 Reply Last reply
                                      1
                                      • R Offline
                                        R Offline
                                        Ryan R
                                        wrote on last edited by
                                        #19

                                        @VRonin Yea it's a bit tricky for me coming from C to C++, especially with Windows!

                                        Everything is getting recognised properly, but there's just one build issue on "fnGetCoreTempInfo(pct);". The error is as follows;

                                        C:\Users\ariie\Desktop\QtProgramming\QtCoreTempTest\QtCoreTempTest\mainwindow.cpp:13: error: undefined reference to `_imp___Z17fnGetCoreTempInfoRP21core_temp_shared_data'
                                        

                                        Thanks again for the responses,
                                        Ryan

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

                                          what are the contents of the CoreTempLib/x86/ folder (I can't trust the docs apparently)?

                                          "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

                                          1 Reply Last reply
                                          1

                                          • Login

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