Q_DISABLE_COPY(Systeminfo),'Systeminfo' does not name a type
-
i am using systeminfo class from Qt installer framework where i got error as 'Systeminfo' does not name a type. here is my systeminfo.cpp file:
#include "systeminfo.h" #include <QSysInfo> namespace QInstaller { SystemInfo::SystemInfo(QObject *parent) : QObject(parent) { } QString SystemInfo::currentCpuArchitecture() const { return QSysInfo::currentCpuArchitecture(); } QString SystemInfo::kernelType() const { return QSysInfo::kernelType(); } QString SystemInfo::kernelVersion() const { return QSysInfo::kernelVersion(); } QString SystemInfo::productType() const { return QSysInfo::productType(); } QString SystemInfo::productVersion() const { return QSysInfo::productVersion(); } QString SystemInfo::prettyProductName() const { return QSysInfo::prettyProductName(); } } // namespace QInstaller
systeminfo.h
#ifndef SYSTEMINFO_H #define SYSTEMINFO_H #include <QObject> namespace QInstaller { class SystemInfo : public QObject { Q_OBJECT Q_DISABLE_COPY(SystemInfo) Q_PROPERTY(QString currentCpuArchitecture READ currentCpuArchitecture CONSTANT) Q_PROPERTY(QString kernelType READ kernelType CONSTANT) Q_PROPERTY(QString kernelVersion READ kernelVersion CONSTANT) Q_PROPERTY(QString productType READ productType CONSTANT) Q_PROPERTY(QString productVersion READ productVersion CONSTANT) Q_PROPERTY(QString prettyProductName READ prettyProductName CONSTANT) public: explicit SystemInfo(QObject *parent = 0); QString currentCpuArchitecture() const; QString kernelType() const; QString kernelVersion() const; QString productType() const; QString productVersion() const; QString prettyProductName() const; }; } // namespace QInstaller #endif // SYSTEMINFO_H
please help to resolve this error.
-
Your header compiles fine here. Apart from this - there's no need for this macro there since QObject is not copyable so SystemInfo is also not copyable.
-
#there's no need for this macro there since QObject is not copyable so SystemInfo is also not copyable.
hello @Christian-Ehrlicher , do you mean that I should remove Q_DISABLE_COPY(SystemInfo) line and compile again? -
#there's no need for this macro there since QObject is not copyable so SystemInfo is also not copyable.
hello @Christian-Ehrlicher , do you mean that I should remove Q_DISABLE_COPY(SystemInfo) line and compile again?@shree_121
Yes. as QObject handles that for you.
Clean your build folder and try to compile again. -
@shree_121 said in Q_DISABLE_COPY(Systeminfo),'Systeminfo' does not name a type:
now i am getting error as 'SystemInfo' has not been declared .
Then you've another problem somewhere else - please show the complete error message and also make sure that no other header defines 'SYSTEMINFO_H'
-
@Christian-Ehrlicher, @mrjj thank you so much now it built successfully, Can you tell me how can i print my OS kernel type in console using QString SystemInfo::kernelType() const.
@shree_121
use std:.cout ?
if console app ?
or qDebug() -
-
Hi
its just a function call so no need for signal or anything complex.
Note that std::xxx is buffered with Qt and you must flush it to print at once.std::cout << "my type=" << QSysInfo::kernelType().toStdString() << std::flush;
this is for the Qt class. but its the same syntax with your wrapper.
-
ohh i used std::cout(console application) but exactly i am not sure where i have to write. Do i have to use signal and slot in main.cpp to execute QString SystemInfo::kernelType() const in systeminfo.cpp. please reply it will really help me.
@shree_121
No signals/slots. Did you try something like:SystemInfo si; std::cout << si.kernelType().toStdString() << std::flush;
As an architectural comment: all the methods of Qt's
QSysInfo
arestatic
. Not sure what you are trying to add by creating a wrapper class deriving fromQObject
, requiring instantiating and with aQObject
parent, etc. For example, you could never have written yourSystemInfo
class and simply calledstd::cout << SystemInfo::kernelType().toStdString() << std::flush;
Up to you.
but its the same syntax with your wrapper.
Similar, but the way he's written it a
SystemInfo
instance will need creating to call his methods. -
@shree_121
No signals/slots. Did you try something like:SystemInfo si; std::cout << si.kernelType().toStdString() << std::flush;
As an architectural comment: all the methods of Qt's
QSysInfo
arestatic
. Not sure what you are trying to add by creating a wrapper class deriving fromQObject
, requiring instantiating and with aQObject
parent, etc. For example, you could never have written yourSystemInfo
class and simply calledstd::cout << SystemInfo::kernelType().toStdString() << std::flush;
Up to you.
but its the same syntax with your wrapper.
Similar, but the way he's written it a
SystemInfo
instance will need creating to call his methods. -
@jonb
thx for clearing up the difference between needing an instance and having static functions. :)
Its an important distinction.@mrjj
The OP's instance approach would be fine if/when he has something to put in the instance to make it have a point. He may well do that, just at the moment there is no indication of what he might store in it, nor what connection it would have to aQObject
or parent. Anyway I just mentioned so that he is aware he will need to create an instance, which he might not be. -
@mrjj
The OP's instance approach would be fine if/when he has something to put in the instance to make it have a point. He may well do that, just at the moment there is no indication of what he might store in it, nor what connection it would have to aQObject
or parent. Anyway I just mentioned so that he is aware he will need to create an instance, which he might not be.