Solved Core Temp Shared Memory in Qt C++ - Windows
-
@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 usingCORE_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 viamainwindow.h
, which is fine. But when you ask Creator to read inGetCoreTempinfo.h
to view on its own, it might give warnings withoutwindows.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)?
-
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 -
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.";
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.
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?