Qt gets Windows memory information

Source: Internet
Author: User

By calling the Windows API to get Windows memory information and displaying it on the interface, you can see that the result is correct by comparing it with the Windows Memory Manager.

The interface effect of the implemented gadget is compared with the memory manager as follows:


Complete code for the implementation:

 #pragma Execution_character_set ("Utf-8") #ifndef qmemoryinfo_h#define qmemoryinfo_h#include <qtwidgets/qwidget># Include <QLabel> #include <QLineEdit> #include <qtimer>class qmemoryinfo:public qwidget{q_ Objectpublic:qmemoryinfo (Qwidget *parent = 0); ~qmemoryinfo ();p rivate:void updateInfo (); Qtimer *m_timer; Qlabel *m_memoryusedlabel; Qlabel *m_totalphyslabel; Qlabel *m_availphyslabel; Qlabel *m_totalpagefilelabel; Qlabel *m_availpagefilelabel; Qlabel *m_totalvirtuallabel; Qlabel *m_availvirtuallabel; Qlabel *m_availexvirtuallabel; Qlineedit *m_memoryusededit; Qlineedit *m_totalphysedit; Qlineedit *m_availphysedit; Qlineedit *m_totalpagefileedit; Qlineedit *m_availpagefileedit; Qlineedit *m_totalvirtualedit; Qlineedit *m_availvirtualedit; Qlineedit *m_availexvirtualedit;}; #endif//Qmemoryinfo_h 
#include "qmemoryinfo.h" #include <QGridLayout> #include <windows.h> #include <sysinfoapi.h> Qmemoryinfo::qmemoryinfo (Qwidget *parent): Qwidget (parent) {M_memoryusedlabel = new Qlabel (this); M_totalphyslabel = New Qlabel (this), M_availphyslabel = new Qlabel (this), M_totalpagefilelabel = new Qlabel (this); M_availpagefilelabel = new Qlabel (this), M_totalvirtuallabel = new Qlabel (this), M_availvirtuallabel = new Qlabel (this); M_availexvirtuallabel = new Qlabel (this), M_memoryusededit = new Qlineedit (this), M_totalphysedit = new Qlineedit (this); m_availphysedit = new Qlineedit (this), M_totalpagefileedit = new Qlineedit (this), M_availpagefileedit = new Qlineedit (this); m_ Totalvirtualedit = new Qlineedit (this), M_availvirtualedit = new Qlineedit (this); m_availexvirtualedit = new Qlineedit ( this); M_memoryusedlabel->settext (QOBJECT::TR ("Memory Utilization:")); M_totalphyslabel->settext ("Total Physical Memory:") m_ Availphyslabel->settext ("Available Physical Memory:"); M_totalpagefilelabel->settext ("Total system submissions:"); m_availpagefilelabel->sEttext ("System commits:"), M_totalvirtuallabel->settext ("Total virtual Memory:"), M_availvirtuallabel->settext ("Available virtual Memory:") m_ Availexvirtuallabel->settext ("Available extended virtual:"); M_memoryusededit->setreadonly (True);m_totalphysedit-> Setreadonly (True); M_availphysedit->setreadonly (true); M_totalpagefileedit->setreadonly (true); m_ Availpagefileedit->setreadonly (True); M_totalvirtualedit->setreadonly (True);m_availvirtualedit-> Setreadonly (True); M_availexvirtualedit->setreadonly (true); Qgridlayout *play = new Qgridlayout (this); int iLine = 0;play->addwidget (M_memoryusedlabel, ILine, 0, 1, 1);p Lay->ad Dwidget (M_memoryusededit, ILine, 1, 1, 3); iline++;p lay->addwidget (M_totalphyslabel, ILine, 0, 1, 1);p lay-> AddWidget (M_totalphysedit, ILine, 1, 1, 3); iline++;p lay->addwidget (M_availphyslabel, ILine, 0, 1, 1);p lay-> AddWidget (M_availphysedit, ILine, 1, 1, 3); iline++;p lay->addwidget (M_totalpagefilelabel, ILine, 0, 1, 1);p lay-> AddWidget (M_totalpagefileedit, ILine, 1, 1, 3); iline++;p Lay->adDwidget (M_availpagefilelabel, ILine, 0, 1, 1);p lay->addwidget (M_availpagefileedit, ILine, 1, 1, 3); iline++;p lay- >addwidget (M_totalvirtuallabel, ILine, 0, 1, 1);p lay->addwidget (M_totalvirtualedit, ILine, 1, 1, 3); iline++; Play->addwidget (M_availvirtuallabel, ILine, 0, 1, 1);p lay->addwidget (M_availvirtualedit, ILine, 1, 1, 3); iline++ ;p Lay->addwidget (M_availexvirtuallabel, ILine, 0, 1, 1);p lay->addwidget (M_availexvirtualedit, ILine, 1, 1, 3); m_ Timer = new Qtimer (this); Connect (M_timer, &qtimer::timeout, this, &qmemoryinfo::updateinfo);m_timer-> Start (100);} Qmemoryinfo::~qmemoryinfo () {}void qmemoryinfo::updateinfo () {Memorystatusex memoryinfo;memoryinfo.dwlength = sizeof (Memoryinfo); GlobalMemoryStatusEx (&memoryinfo); UINT MB = 1024x768 * 1024;m_memoryusededit->settext (Qstring::number (memoryinfo.dwmemoryload). Append ("%")); m_ Totalphysedit->settext (Qstring::number (MEMORYINFO.ULLTOTALPHYS/MB)); M_availphysedit->settext (QString:: Number (memoryinfo.ullavailphyS/MB)); M_totalpagefileedit->settext (Qstring::number (MEMORYINFO.ULLTOTALPAGEFILE/MB)); m_availPageFileEdit- >settext (Qstring::number (MEMORYINFO.ULLTOTALPAGEFILE/MB-MEMORYINFO.ULLAVAILPAGEFILE/MB)); m_ Totalvirtualedit->settext (Qstring::number (MEMORYINFO.ULLTOTALVIRTUAL/MB)); M_availvirtualedit->settext ( Qstring::number (MEMORYINFO.ULLAVAILVIRTUAL/MB)); M_availexvirtualedit->settext (QString::number ( MEMORYINFO.ULLAVAILEXTENDEDVIRTUAL/MB)); Update ();}
AC qq:1245178753

This address: http://blog.csdn.net/u011417605/article/details/51564802

SOURCE Download: http://download.csdn.net/detail/u011417605/9538726

Qt gets Windows memory information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.