QT Qulonglong Fehler



  • Hi,

    ich arbeite gerade das Buch Mastering Qt 5. Im Kapitel 2 kann ich folgenden Code nicht kompilieren:

    double SysInfoWindowsImpl::memoryUsed()
    {
       MEMORYSTATUSEX memoryStatus;
       memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
       GlobalMemoryStatusEx(&memoryStatus);
    
       qulonglong memoryPhysicalUsed =
               memoryStatus.ullTotalPhys - memoryStatus.ullAvailPhys;
       return (double)memoryPhysicalUsed/double(memoryStatus.ullTotalPhys) * 100.0;
    }
    
    

    Fehler: unknown Type 'qulonglong'

    "..\V2\sysinfowindowsimpl.cpp:16:5: note: suggested alternative: 'u_long'"

    Wenn ich qulonglong durch u_long ersetze, kommt ein anderer Fehler:

    D:\maiks\QtCreator\V2\sysinfowindowsimpl.cpp:-: Fehler: undefined reference to `vtable for SysInfoWindowsImpl'

    Hat jemand eine Idee, was der Grund dafür sein kann ?

    Sysinfo.h

    #ifndef SYSINFO_H
    #define SYSINFO_H
    
    
    class SysInfo
    {
    public:
        SysInfo();
        virtual ~SysInfo();
    
        virtual void init() = 0;
        virtual double cpuLoadAverage() = 0;
        virtual double memoryUsed() = 0;
    };
    
    #endif // SYSINFO_H
    

    Sysinfo.cpp

    #include "sysinfo.h"
    
    SysInfo::SysInfo()
    {
    
    }
    
    SysInfo::~SysInfo()
    {
    
    }
    

    SysInfoWindowsImpl

    #ifndef SYSINFOWINDOWSIMPL_H
    #define SYSINFOWINDOWSIMPL_H
    
    #include "sysinfo.h"
    
    class SysInfoWindowsImpl : public SysInfo
    {
    public:
        SysInfoWindowsImpl();
    
        void init() override;
    
    
        // SysInfo interface
    public:
        double cpuLoadAverage() override;
        double memoryUsed() override;
    };
    
    #endif // SYSINFOWINDOWSIMPL_H
    

    SysInfoWindowsImpl.cpp

    #include "sysinfowindowsimpl.h"
    
    #include <windows.h>
    
    SysInfoWindowsImpl::SysInfoWindowsImpl() : SysInfo()
    {
    
    }
    
    
     double SysInfoWindowsImpl::memoryUsed()
    {
        MEMORYSTATUSEX memoryStatus;
        memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
        GlobalMemoryStatusEx(&memoryStatus);
    
        qulong memoryPhysicalUsed =
                memoryStatus.ullTotalPhys - memoryStatus.ullAvailPhys;
        return (double)memoryPhysicalUsed/double(memoryStatus.ullTotalPhys) * 100.0;
    }
    


  • Google sagt, das qulonglong im Header <QtGlobal> zu finden ist. Den müsstest du dafür includieren.

    Der zweite Fehler ist ein Linker Fehler. Du musst alle "pure virtual" Funktionen in deiner Ableitung definieren und wenn ich das gerade richtig sehe, fehlen cpuLoadAverage() und init()


Anmelden zum Antworten