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) { ... }