문제

I'm working with OpenCV and Qt 5. I need to pass a mouse callback to a namedwindow for some work I'm doing. However, I can't get it to see any of the private member variables of my class.

Here's some code:

class testWizard : public QWizard
{
  Q_OBJECT


  public:
   testWizard();
  ~testWizard();

   friend void mouseHandler(int, int, int, void*);



   private:

    cv::Mat preview;

    bool drag; 
    cv::Rect rect;   
};

The friend function:

void mouseHandler(int event, int x, int y, void* param)
{

 cv::Point p1, p2;

 if(event == CV_EVENT_LBUTTONDOWN && !drag)
 {
   p1 = cv::Point(x,y);
   drag = true;
 }

 if(event == CV_EVENT_LBUTTONDOWN && drag)
 {
   cv::Mat temp;
   preview.copyTo(temp);
 }

}

I don't know what I'm doing wrong. I'm pretty sure this is the correct way to declare this. It is telling me that preview, and drag are undeclared identifiers. Unfortunately I need to do it this way since I need access to the private members and passing a pointer to a member function isn't possible because of the hidden this argument.

Can anyone help? Thank you!

도움이 되었습니까?

해결책

With the friend declaration your function would have access to the members of a testWizard object. However, you still need to provide an object or a pointer to such an object to access the variables:

testWizard* wizard = getTestWizard(); // no idea how to do that
if(event == CV_EVENT_LBUTTONDOWN && !wizard->drag) { ... }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top