Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Core Temp Shared Memory in Qt C++ - Windows



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • 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



  • 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



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



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



  • @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?



  • 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]);
    


  • 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



  • 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



  • can you post the contents of GetCoreTempinfo.h?



  • 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



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



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



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



  • 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]);
    


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



  • 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]);
    


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



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



  • @VRonin

    b505045b-f13b-464a-8f52-3f675be3f2b8-image.png

    f3be67de-f418-474e-9378-1ac87c7701b9-image.png

    Thanks,
    Ryan



  • I finally gave up and actually downloaded the library otherwise we'll take forever.
    They are incompatible with MinGW, good old @SGaist is always right.
    You need to use Visual Studio or visual studio build tools to link against it



  • @VRonin

    That was the clue I needed! I changed to kit to MSVC2017 and it started working perfectly, with your modifications!

    I'll get it all on a GUI, post the project here and mark the topic as solved!

    I can't thank you enough!

    Ryan



  • @VRonin said in Core Temp Shared Memory in Qt C++ - Windows:

    good old @SGaist is always right.

    I know, it's really irritating isn't it? ;-)



  • At least we got there in the end!

    For anyone else wanting to make a PC monitoring system, I am releasing the full test project for Core Temp Shared Memory below.

    • Make sure Core Temp is installed & running. I use the following settings: enable plug-ins, start core temp with Windows, start core temp minimized.
    • You must tick "Enable global shared memory (SNMP)" inside Core Temp advanced settings!
    • Make sure you're using MSVC compiler; I used 2017 32-bit on Qt 5.14.2, Windows 10 64-bit .
    • Download the library and put it somewhere useful (No spaces, in a directory with a short file path).
    • Import the library by right clicking the project; external library, untick Linux & Mac.
    • Point the library file path to the folder corrosponding to your architecture (x86 or x64), depending on your compiler. Example "C:\CoreTempLib\x86".
    • Point the include path to the root directory of the library (should have Borland, x64, x86 & GetCoreTempInfo.h inside). Example "C:\CoreTempLib".
    • Now you can insert the header files "windows.h" and "GetCoreTempInfo.h" and use the library.
                CORE_TEMP_SHARED_DATA* pct=&ct;
                fnGetCoreTempInfo(pct);
    
    qDebug() << "Core 0 Temperature: "<< ct.fTemp[0] << " C.";
    

    f78f9358-9b96-4b7f-acee-ba8452ab49ab-image.png

    I made this quick project with C++/XML. It uses QThread and grabs the CPU data every second and pushes it to the GUI, without blocking it. Some of the code is messy, but it's just a quick example so other people don't have to go through this! If I've done anything dramatically wrong (like use Mutex incorrectly), I'm not sure if people can still post on this topic after I mark it as solved, so just PM me and I should be able to make the edits. Feel free to use any of the code below however you want.

    QtCoreTempTest.pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
        cputhread.cpp \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        cputhread.h \
        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
    
    
    win32: LIBS += -L$$PWD/../../../../../../CoreTempLib/x86/ -lGetCoreTempInfo
    
    INCLUDEPATH += $$PWD/../../../../../../CoreTempLib
    DEPENDPATH += $$PWD/../../../../../../CoreTempLib/x86
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QDebug>
    #include <QString>
    #include <QVariant>
    #include <QByteArray>
    #include <QMutex>
    #include <QThread>
    
    #include <stdio.h>
    
    #include "cputhread.h"
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
        CPUThread *mCPUThread;
    
    public slots:
        void onValueChanged(int, int, int, int, float, float, float, float, int, int, float, float, float, float, char, char, QString);
    
    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);
    
        ui->labelInfo->setText("You must install the Core Temp SDK and import the libraries for this to work! <br /> <a href=\"http://alcpu.com/CoreTemp/developers.html\">SDK</a> <br /><br /> <a href=\"https://forum.qt.io/topic/115469/core-temp-shared-memory-in-qt-c-windows/24\">Forum</a>   ");
        ui->labelInfo->setTextFormat(Qt::RichText);
        ui->labelInfo->setTextInteractionFlags(Qt::TextBrowserInteraction);
        ui->labelInfo->setOpenExternalLinks(true);
    
        mCPUThread = new CPUThread(this);
    
        connect(mCPUThread, SIGNAL(valueChanged(int, int, int, int, float, float, float, float, int, int, float, float, float, float, char, char, QString)), this, SLOT(onValueChanged(int, int, int, int, float, float, float, float, int, int, float, float, float, float, char, char, QString)));
    
        mCPUThread->start();
    }
    
    void MainWindow::onValueChanged(int cpuLoad0, int cpuLoad1, int cpuLoad2, int cpuLoad3, float cpuTemp0, float cpuTemp1, float cpuTemp2, float cpuTemp3, int cpuTjMax, int cpuCoreCount, float cpuID, float cpuFsbSpeed, float cpuMultiplier, float cpuSpeed, char cpuFah, char cpuDeltaToMax, QString cpuName)
    {
        qDebug() << "From Thread: " << cpuLoad0 << "," << cpuLoad1 << "," << cpuLoad2 << "," << cpuLoad3 << "," << cpuTemp0 << "," << cpuTemp1 << "," << cpuTemp2 << "," << cpuTemp3 << "," << cpuTjMax << "," << cpuCoreCount << "," <<  cpuID << "," << cpuFsbSpeed << "," << cpuMultiplier << "," << cpuSpeed << "," << cpuFah << "," << cpuDeltaToMax << "," << cpuName << ".";
        ui->cpuLoad0->setValue(cpuLoad0);
        ui->cpuLoad1->setValue(cpuLoad1);
        ui->cpuLoad2->setValue(cpuLoad2);
        ui->cpuLoad3->setValue(cpuLoad3);
    
        ui->cpuTemp0->setValue(cpuTemp0);
        ui->cpuTemp1->setValue(cpuTemp1);
        ui->cpuTemp2->setValue(cpuTemp2);
        ui->cpuTemp3->setValue(cpuTemp3);
    
        ui->labelTjMax->setText(QString::number(cpuTjMax));
        ui->labelCoreCount->setText(QString::number(cpuCoreCount));
        ui->labelId->setText(QString::number(cpuID));
        ui->labelFsbSpeed->setText(QString::number(cpuFsbSpeed));
        ui->labelMultiplier->setText(QString::number(cpuMultiplier));
        ui->labelSpeed->setText(QString::number(cpuSpeed));
        ui->labelName->setText(cpuName);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    cputhread.h

    #ifndef CPUTHREAD_H
    #define CPUTHREAD_H
    
    
    #include <QObject>
    #include <QThread>
    #include <windows.h>
    #include <GetCoreTempInfo.h>
    
    // Counts from 1 to 100.
    
    class CPUThread : public QThread
    {
    Q_OBJECT
    public:
    CPUThread();
    explicit CPUThread(QObject *parent = 0, bool b = false);
    void run();
    
    // if Stop = true, the thread will break
    // out of the loop, and will be disposed
    bool Stop;
    
    signals:
    // To communicate with Gui Thread
    // we need to emit a signal
    void valueChanged(int, int, int, int, float, float, float, float, int, int, float, float, float, float, char, char, QString);
    
    public slots:
    
    };
    #endif // CPUTHREAD_H
    

    cputhread.cpp

    #include "cputhread.h"
    #include <QDebug>
    #include <QMutex>
    
    #include<stdio.h>
    
        CPUThread::CPUThread(QObject *parent, bool b) :
            QThread(parent), Stop(b)
        {
        }
    
       // run() will be called when a thread starts
        void CPUThread::run()
        {
            for(int i = 0; i <= 100; i++)
            {
                QMutex mutex;
                // prevent other threads from changing the "Stop" value
                mutex.lock();
                if(this->Stop) break;
                mutex.unlock();
    
                CORE_TEMP_SHARED_DATA ct;
                CORE_TEMP_SHARED_DATA* pct=&ct;
                fnGetCoreTempInfo(pct);
    
    
    
                char cName[100] = "-1";
                strcpy(cName, ct.sCPUName);
                QString cpuName(cName);
    
                emit valueChanged(ct.uiLoad[0], ct.uiLoad[1], ct.uiLoad[2], ct.uiLoad[3], ct.fTemp[0], ct.fTemp[1], ct.fTemp[2], ct.fTemp[3], ct.uiTjMax[0], ct.uiCoreCnt, ct.fVID, ct.fFSBSpeed, ct.fMultipier, ct.fCPUSpeed, ct.ucFahrenheit, ct.ucDeltaToTjMax, cpuName);
    
                this->sleep(1);
    
                if(i > 99)
                {
                    i = 0;
                }
            }
            run();
          }
    

    main.cpp

    #include "mainwindow.h"
    
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
    
    

    mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>712</width>
        <height>246</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Core Temp Shared Memory</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <widget class="QProgressBar" name="cpuLoad0">
        <property name="geometry">
         <rect>
          <x>40</x>
          <y>40</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuLoad1">
        <property name="geometry">
         <rect>
          <x>40</x>
          <y>80</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuLoad2">
        <property name="geometry">
         <rect>
          <x>40</x>
          <y>120</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuLoad3">
        <property name="geometry">
         <rect>
          <x>40</x>
          <y>160</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
       </widget>
       <widget class="QLabel" name="label">
        <property name="geometry">
         <rect>
          <x>40</x>
          <y>10</y>
          <width>151</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>Physical Core Load</string>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuTemp2">
        <property name="geometry">
         <rect>
          <x>200</x>
          <y>120</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
        <property name="format">
         <string>%p C</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_2">
        <property name="geometry">
         <rect>
          <x>200</x>
          <y>10</y>
          <width>151</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>Physical Core Load</string>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuTemp0">
        <property name="geometry">
         <rect>
          <x>200</x>
          <y>40</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="styleSheet">
         <string notr="true"/>
        </property>
        <property name="value">
         <number>0</number>
        </property>
        <property name="format">
         <string>%p C</string>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuTemp3">
        <property name="geometry">
         <rect>
          <x>200</x>
          <y>160</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
        <property name="format">
         <string>%p C</string>
        </property>
       </widget>
       <widget class="QProgressBar" name="cpuTemp1">
        <property name="geometry">
         <rect>
          <x>200</x>
          <y>80</y>
          <width>118</width>
          <height>23</height>
         </rect>
        </property>
        <property name="value">
         <number>0</number>
        </property>
        <property name="format">
         <string>%p C</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_3">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>10</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>tjMax:</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelTjMax">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>10</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_4">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>40</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>Core Count:</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelCoreCount">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>40</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelInfo">
        <property name="geometry">
         <rect>
          <x>570</x>
          <y>10</y>
          <width>121</width>
          <height>201</height>
         </rect>
        </property>
        <property name="text">
         <string>Loading...</string>
        </property>
        <property name="alignment">
         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
        </property>
        <property name="wordWrap">
         <bool>true</bool>
        </property>
       </widget>
       <widget class="QLabel" name="label_6">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>70</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>ID:</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_7">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>100</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>FSB Speed:</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_8">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>130</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>Multiplier: </string>
        </property>
       </widget>
       <widget class="QLabel" name="label_9">
        <property name="geometry">
         <rect>
          <x>350</x>
          <y>160</y>
          <width>121</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>CPU Speed:</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelId">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>70</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelFsbSpeed">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>100</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelMultiplier">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>130</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelSpeed">
        <property name="geometry">
         <rect>
          <x>470</x>
          <y>160</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelSpeed_2">
        <property name="geometry">
         <rect>
          <x>520</x>
          <y>160</y>
          <width>41</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>MHz</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_5">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>10</y>
          <width>16</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>#</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_10">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>40</y>
          <width>16</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>0</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_11">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>80</y>
          <width>16</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>1</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_12">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>120</y>
          <width>16</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>2</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_13">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>160</y>
          <width>16</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>3</string>
        </property>
       </widget>
       <widget class="QLabel" name="labelName">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>200</y>
          <width>541</width>
          <height>16</height>
         </rect>
        </property>
        <property name="text">
         <string>Name</string>
        </property>
       </widget>
      </widget>
      <widget class="QStatusBar" name="statusbar"/>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    I'd like to say a big thank you to @SGaist, @JonB & especially @VRonin. I'd probaly still be scratching my head, wondering why the structure still isn't being populated without you guys!



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

    For anyone else wanting to make a PC monitoring system, I am releasing the full test project for Core Temp Shared Memory below.

    All looks good! I don't get hardware/devices, so this is novel for me. Is this used for measuring my core temperature to see if I have virus or something?



  • Well originally I used LabVIEW and created this:

    692aa16c-6c00-4f79-be97-2dcfa011b58f-image.png

    The aim was to create a program that sticks to the Desktop and can be overlayed on top of games. The issue with LabVIEW is that the runtime engine is quite bloated, so running that program with 4K games wasn't an option without losing FPS.

    My plan is to re-create the program in Qt C++ with XML and CSS.

    I'm sure there are a few other gamers out there that are curious about making something like this, since you can get it to display warnings, Windows notifications, ect.. with Qt.

    I'm also going to hook it up to my dedicated server with MySQL, so all of the data collected gets logged to a web panel. Then I can make a "lite" version of the program on my companies embedded PCs around the world for real-time data logging, remote control and firmware updates.


Log in to reply