May 7, 2012

maplesyrup23 maplesyrup23
Lab Rat
15 posts

[SOLVED] QObject::QObject’ : cannot access private member declared in class ‘QObject’ !

 

Some of the functions in this class I defined uses some Qt children methods, so I had to have the Q_OBJECT macro. However, this is the sole error that comes up when I attempt to compile, and I neither know how to interpret it nor to fix it. Any input?

  1.  #ifndef HARDTRIGGER_H
  2. #define HARDTRIGGER_H
  3.  
  4. #include
  5. #include <QObject>
  6.  
  7. class tCamera : public QObject
  8. {
  9.     Q_OBJECT
  10. public:
  11.     unsigned long   UID;
  12.     tPvHandle       Handle;
  13.     tPvFrame        Frame;
  14.     tPvUint32       Counter;
  15.     char            Filename[20];
  16.     bool            Abort;
  17. private slots:
  18.     void WaitForCamera();
  19.     bool CameraGet();
  20.     bool CameraSetup();
  21.     void CameraUnsetup();
  22.     bool CameraStart();
  23.     void CameraStop();
  24.     bool CameraSnap();
  25. };
  26. #endif // HARDTRIGGER_H

1 reply

May 7, 2012

Zlatomir Zlatomir
Hobby Entomologist
361 posts

That must happen because the default constructor of QObject is private, so define an constructor for your class to pass a QObject* parent to the QObject constructor

  1. class tCamera : public QObject
  2. {
  3.     Q_OBJECT
  4. public:
  5.     tCamera(QObject* parent = 0); //pass parent to QObject's c-tor in the definition of your c-tor
  6. //...

Also you should make sure to disable the copy for your class using q_disable_copy or private copy c-tor and assignment operator [qt-project.org]

 
  ‹‹ Qt method swizzling      [SOLVED] Undefined Linker Error LNK1117: The compiler seems to toss out lines of my PRO file. ››

You must log in to post a reply. Not a member yet? Register here!