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. Q_DISABLE_COPY(Systeminfo),'Systeminfo' does not name a type
Forum Updated to NodeBB v4.3 + New Features

Q_DISABLE_COPY(Systeminfo),'Systeminfo' does not name a type

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 4 Posters 1.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    shree_121
    wrote on last edited by shree_121
    #1

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shree_121
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • S shree_121

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @shree_121
          Yes. as QObject handles that for you.
          Clean your build folder and try to compile again.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shree_121
            wrote on last edited by
            #5

            now i am getting error as 'SystemInfo' has not been declared .

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shree_121
                wrote on last edited by
                #7

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

                mrjjM 1 Reply Last reply
                0
                • S shree_121

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @shree_121
                  use std:.cout ?
                  if console app ?
                  or qDebug()

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shree_121
                    wrote on last edited by shree_121
                    #9

                    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.

                    JonBJ 1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      1
                      • S shree_121

                        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.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #11

                        @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 are static. Not sure what you are trying to add by creating a wrapper class deriving from QObject, requiring instantiating and with a QObject parent, etc. For example, you could never have written your SystemInfo class and simply called

                        std::cout << SystemInfo::kernelType().toStdString() << std::flush;
                        

                        Up to you.

                        @mrjj

                        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.

                        mrjjM 1 Reply Last reply
                        2
                        • JonBJ JonB

                          @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 are static. Not sure what you are trying to add by creating a wrapper class deriving from QObject, requiring instantiating and with a QObject parent, etc. For example, you could never have written your SystemInfo class and simply called

                          std::cout << SystemInfo::kernelType().toStdString() << std::flush;
                          

                          Up to you.

                          @mrjj

                          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.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @jonb
                          thx for clearing up the difference between needing an instance and having static functions. :)
                          Its an important distinction.

                          JonBJ 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @jonb
                            thx for clearing up the difference between needing an instance and having static functions. :)
                            Its an important distinction.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @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 a QObject or parent. Anyway I just mentioned so that he is aware he will need to create an instance, which he might not be.

                            mrjjM 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @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 a QObject or parent. Anyway I just mentioned so that he is aware he will need to create an instance, which he might not be.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @jonb
                              Indeed.
                              Also, such wrapper would be useful for exposing it to QML.

                              JonBJ 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @jonb
                                Indeed.
                                Also, such wrapper would be useful for exposing it to QML.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #15

                                @mrjj said in Q_DISABLE_COPY(Systeminfo),'Systeminfo' does not name a type:

                                Also, such wrapper would be useful for exposing it to QML.

                                Ah, that I would not have known. As I said, OP may have his reasons.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  shree_121
                                  wrote on last edited by
                                  #16

                                  @mrjj , @JonB Both ways worked for me. Thank you.

                                  1 Reply Last reply
                                  1

                                  • Login

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