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 Update on Monday, May 27th 2025

Core Temp Shared Memory in Qt C++ - Windows

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 4 Posters 4.2k Views
  • 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 5 Jun 2020, 14:33 last edited by Ryan R 6 May 2020, 14:35
    #21

    @VRonin

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

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

    Thanks,
    Ryan

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 5 Jun 2020, 15:19 last edited by
      #22

      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

      "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

      J 1 Reply Last reply 5 Jun 2020, 16:19
      4
      • R Offline
        R Offline
        Ryan R
        wrote on 5 Jun 2020, 15:51 last edited by Ryan R 6 May 2020, 15:51
        #23

        @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

        1 Reply Last reply
        0
        • V VRonin
          5 Jun 2020, 15:19

          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

          J Offline
          J Offline
          JonB
          wrote on 5 Jun 2020, 16:19 last edited by
          #24

          @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? ;-)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ryan R
            wrote on 5 Jun 2020, 19:04 last edited by Ryan R 6 May 2020, 19:24
            #25

            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!

            J 1 Reply Last reply 5 Jun 2020, 19:41
            2
            • R Ryan R
              5 Jun 2020, 19:04

              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!

              J Offline
              J Offline
              JonB
              wrote on 5 Jun 2020, 19:41 last edited by JonB 6 May 2020, 19:41
              #26

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

              1 Reply Last reply
              1
              • R Offline
                R Offline
                Ryan R
                wrote on 5 Jun 2020, 20:05 last edited by Ryan R
                #27

                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.

                1 Reply Last reply
                0

                21/27

                5 Jun 2020, 14:33

                • Login

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