Ask Your Question

onMouse function error

asked 2018-05-30 02:25:01 -0500

billqu gravatar image

updated 2018-05-30 02:29:46 -0500

LBerger gravatar image

my code

 void CBeautyDlg::onMouse(int events, int x, int y, int flag, void* ustg) {...}

 void CBeautyDlg::OnBnClickedButton6(
 inputImage = m_Image;

inputImage_clone = inputImage.clone();
createMosaicImage(inputImage, inputImage_mosaic, neightbourhood);

namedWindow("myshowWnd", 0);
setMouseCallback("myshowWnd", onMouse,0);

but error on setMouseCallback("myshowWnd", onMouse,0);

notify below:

"Void (CBeautyDlg:: *) (int events, int x, int y, int flag, void void)" type of real participation "type:" type parameter is incompatible.

How to fix the error?

Thank you.

edit retag flag offensive close merge delete


You cannot use a method for onMouse

You can try something as :

void onMouse(int events, int x, int y, int flag, void* ustg)
 CBeautyDlg *ptr=( CBeautyDlg *)ustg;
LBerger gravatar imageLBerger ( 2018-05-30 02:31:48 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-05-30 02:41:50 -0500

berak gravatar image

updated 2018-05-30 03:14:10 -0500

it wants a static function as mouse callback, while you have a class member function (which would need the classe's this pointer to work properly)

it needs some indirection:

class CBeautyDlg {

    void realMouse(int events, int x, int y, int flag) {
         // your event handling code

    // static wrapper (does NOT need "this")
    static void onMouse(int events, int x, int y, int flag, void* me) {
        // "me" is, what we fed into setMouseCallback() below:
        CBeautyDlg * that = (CBeautyDlg *)(me); // cast back to proper class
        that->realMouse(events, x, y, flag); // call class member

    void OnBnClickedButton6() {
         setMouseCallback("myshowWnd", onMouse, (void*)this);

edit flag offensive delete link more


Thank you very much!

billqu gravatar imagebillqu ( 2018-05-30 03:10:05 -0500 )edit

there were some stray :: things in there, fixed now !

berak gravatar imageberak ( 2018-05-30 03:14:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-30 02:25:01 -0500

Seen: 124 times

Last updated: May 30 '18