Hi
I'm working on a QT Coin/SoQt widget. I'm confused about a static hack to the widget part I made which works, but I don't understand why. Doesn't seem right, but it works. I'm trying to do it the correct way. Hoping to get some advice. Sorry if this is a bit O.T. since QT part is not shown.

The problem is with the function dragger_moved.


If I declare the function dragger_moved in .h as
void dragger_moved(void * data, SoDragger * dragger);
as non-static, and have the .cpp function also as non-static
void Model::dragger_moved(void*, SoDragger*) I get an error.
"error: no matching function for call to 'SoDragPointDragger::addMotionCallback"

But if I declare the function dragger_moved in .h as static:
static void dragger_moved(void * data, SoDragger * dragger);
and also have the .cpp function as static:
static void Model::dragger_moved(void*, SoDragger*)
I get a different error:
"error: cannot declare member function 'static void Model::dragger_moved(void*, SoDragger*)' to have static linkage"

I came up with a hack of declaring the function dragger_moved in .h as static
static void dragger_moved(void * data, SoDragger * dragger);
but using non-static in the .cpp function as
void Model::dragger_moved(void*, SoDragger*)
and this gets thru the compiler.

That doesn't seem the best way to do it. Ideally the dragger_moved function should be static since it deals with the widget's scene graph.

Qt Code:
  1. model.h
  2.  
  3. static SoDragPointDragger ** draggers = NULL;
  4. ...
  5. class Model : public SoQtExaminerViewer
  6. {
  7.  
  8. public:
  9.  
  10. Model( QWidget *parent = NULL, const char *name=NULL, const SbBool embed=TRUE);
  11. ~Model(void);
  12.  
  13. struct dragcb_data;
  14. static void dragger_moved(void * data, SoDragger * dragger);
  15. void setDefaultScene();
  16. ...
  17.  
  18. -----------
  19. model.cpp
  20. #include <model.h>
  21.  
  22. Model::Model( QWidget *parent, const char * name, const SbBool embed)
  23. : SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_ALL, SoQtViewer::BROWSER, TRUE)
  24. {
  25. ...
  26. struct Model::dragcb_data {
  27. unsigned int idx;
  28. };
  29.  
  30. void Model::dragger_moved(void * data, SoDragger * dragger)
  31. {
  32. SoDragPointDragger * dpd = (SoDragPointDragger *)dragger;
  33. struct dragcb_data * cbdata = (struct dragcb_data *)data;
  34. SbVec3f v = dpd->translation.getValue();
  35. ctrlpts->point.set1Value(cbdata->idx, v[0], v[1], v[2]);
  36. }
  37.  
  38. void Model::setDefaultScene(void) {
  39.  
  40. ...
  41. struct dragcb_data * data = new struct dragcb_data;
  42. data->idx = i;
  43. dpd->addMotionCallback(dragger_moved, data);
  44. dpd->translation.setValue(pts[i]);
  45. root->addChild(dpd);
  46. ...
  47. }
To copy to clipboard, switch view to plain text mode