Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Coin3d + Qt: SIGLNALs and SLOTs

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Coin3d + Qt: SIGLNALs and SLOTs

    In my attempts last week to render a Coin3d scene in a Qt application, I used Qt's hellogl demo program as a template and modified it. The Coin scene renders nicely now, but I cannot get it to recognize Qt's signals & slots. My window.cpp file still contains this:

    Qt Code:
    1. connect(xSlider, SIGNAL(valueChanged(int)), coinWidget, SLOT(setXRotation(int)));
    2. connect(coinWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 
    My CoinWidget constructor looks like this:

    Qt Code:
    1. CoinWidget::CoinWidget(QWidget *parent) : QMainWindow(parent)
    2. {
    3. SoQt::init(this);
    4.  
    5. SoSeparator *root = new SoSeparator;
    6. SoRotationXYZ *rootRot = new SoRotationXYZ;
    7. root->ref();
    8.  
    9. root->addChild(rootRot);
    10. root->addChild(new SoCone);
    11.  
    12. rootRot->angle=xRot;
    13.  
    14. SoQtExaminerViewer *eviewer = new SoQtExaminerViewer(this);
    15. eviewer->setDecoration(false);
    16. eviewer->setSceneGraph(root);
    17. eviewer->show();
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    ...such that the xRot variable *should* be modified by moving the slider (and thus cause my model to rotate), but it's not happening. I'm thinking that when using SoQt, there may be an additional step involved. Any suggestions?
    Last edited by wysota; 7th May 2007 at 15:05. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Does connect outputs any warnings/errors?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Did you remember about adding Q_OBJECT macro to your class header?

  4. The following user says thank you to wysota for this useful post:

    liuminghacker (15th July 2009)

  5. #4
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    yes, I've included the Q_OBJECT macro. Marcel, no errors that I know of, but I wouldn't expect any: the signal/slot code and functions are lifted straight from the HelloGL demo, so I think everything is working fine there. I'll add a QLCDNumber widget now, just to make sure the xRot value is changing when I move the slider. (although I put a temporary exit() statement in the setXRotation() function just to make sure it was being called, and it was.)

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Trey using qDebug in the suspect slots to see if they are called. You should open your app from the console in this case.

  7. #6
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    What are setRotationX/Y/Z actually doing?

    Pete

  8. #7
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Thanks for the tip, Marcel: i hadn't used qDebug before; very useful. As it turns out, the function was being called but the values weren't updating properly. That's fixed now, but it's still not working, but at least now I know the problem is on the Coin3d side, which I think I've almost got worked out.

    Pete- the model in my Coin3d scene should rotate around the X, Y, or Z axis when setRotationX/Y/Z are called.

  9. #8
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    As a techie I was sort of expecting a code listing - but from your answer, I could see you having a great future in "requirements"

    Have you sorted it yet?

    Pete

  10. #9
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    No, I've not sorted it yet.

    I've learned that I need to add a Coin3d field, SoSFFloat, to my program, and use this (rather than a standard float) to update the rotation value. Here's the code-

    coinwidget.h
    Qt Code:
    1. #ifndef COINWIDGET_H
    2. #define COINWIDGET_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. #include <Inventor/Qt/SoQt.h>
    7. #include <Inventor/nodes/SoSeparator.h>
    8. #include <Inventor/nodes/SoRotationXYZ.h>
    9. #include <Inventor/nodes/SoCone.h>
    10. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    11. #include <Inventor/fields/SoSFFloat.h>
    12.  
    13. class CoinWidget : public QMainWindow
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. CoinWidget(QWidget *parent = 0);
    19. ~CoinWidget();
    20.  
    21. QSize minimumSizeHint() const;
    22. QSize sizeHint() const;
    23.  
    24. float deg2rad(int angle) { return (angle * 3.1416/180.00); }
    25.  
    26. // SoSFFloat xRot;
    27.  
    28. public slots:
    29. void setXRotation(int angle);
    30. void setYRotation(int angle);
    31. void setZRotation(int angle);
    32.  
    33. signals:
    34. void xRotationChanged(int angle);
    35. void yRotationChanged(int angle);
    36. void zRotationChanged(int angle);
    37.  
    38. protected:
    39.  
    40. private:
    41. void normalizeAngle(int *angle);
    42.  
    43. };
    44.  
    45. #endif
    To copy to clipboard, switch view to plain text mode 

    coinwidget.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <Inventor/Qt/SoQt.h>
    3. #include <Inventor/nodes/SoSeparator.h>
    4. #include <Inventor/nodes/SoRotationXYZ.h>
    5. #include <Inventor/nodes/SoCone.h>
    6. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    7. #include <Inventor/fields/SoSFFloat.h>
    8.  
    9. #include <math.h>
    10.  
    11. #include "coinwidget.h"
    12.  
    13. CoinWidget::CoinWidget(QWidget *parent) : QMainWindow(parent)
    14. {
    15.  
    16. SoQt::init(this);
    17.  
    18. SoSeparator *root = new SoSeparator;
    19. SoRotationXYZ *rootRot = new SoRotationXYZ;
    20.  
    21. // rootRot->angle=xRot.getValue();
    22. root->ref();
    23.  
    24. root->addChild(rootRot);
    25. root->addChild(new SoCone);
    26.  
    27. SoQtExaminerViewer *eviewer = new SoQtExaminerViewer(this);
    28. eviewer->setDecoration(false);
    29. eviewer->setSceneGraph(root);
    30. eviewer->show();
    31.  
    32. }
    33.  
    34. CoinWidget::~CoinWidget()
    35. {
    36. }
    37.  
    38. QSize CoinWidget::minimumSizeHint() const {
    39. return QSize(200, 200);
    40. }
    41.  
    42. QSize CoinWidget::sizeHint() const {
    43. return QSize(400, 400);
    44. }
    45.  
    46. void CoinWidget::setXRotation(int angle)
    47. {
    48. float a = deg2rad(angle);
    49. qDebug("angle = %.4f\n", a);
    50.  
    51. /*
    52.   if(a != rootRot->angle.getValue()) {
    53.   rootRot->angle=a;
    54.   }
    55. */
    56. }
    57.  
    58. void CoinWidget::setYRotation(int angle) {
    59. }
    60.  
    61. void CoinWidget::setZRotation(int angle) {
    62. }
    To copy to clipboard, switch view to plain text mode 

    you can ignore the setXRotation() function for now. My problem is: if I simply uncomment the "SoSFFloat xRot;" statement in the class declaration, my program will compile/link but I get a "Microsoft Visual C++ Runtime Library" dialog-box error message:

    Assertion failed!

    Program c:\qt_tutorial\testprog.exe
    File: c:\orig_coindir\source\Coin-2.4.6\src\fields\sosffloat.cpp
    Line: 49
    Expression: SoSFFloat::classTypeId != SoType::badType()
    If I declare the same variable within the CoinWidget constructor, however, it runs fine... the problem here, though, is that I cannot then access the variable from other member functions, notably setXRotation().

    I should mention/say: the file
    File: c:\orig_coindir\source\Coin-2.4.6\src\fields\sosffloat.cpp
    doesn't actually exist. This was the location of my initial Coin3d installation, which has since been deleted. In my Visual Studio project, in the "vsvar32.txt" file, and in my system Environment Variables: this directory doesn't exist! ...so I don't know why it's referring to it here. Anyway, I don't think this is related to my problem, since I only seem to have a problem with the SoSFFloat variable when I declare it in the Class Declaration and not in the constructor.

    Any ideas? Anyone? Buehler?

  11. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Leave xRot a member but try to initialize it somehow( I don't know what ways of initialization are there - but I am sure there is at least one ) in the constructor.

    It seems this is the problem, you use xRot uninitialized.

    Regards

  12. #11
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    You've got one or 2 gotchas in that code. I'm still trying to understand Coin3d myself but there's a few fundamental problems with your code.

    The first problem is that the root of your scenegraph and the rotation node is orphaned once you've left the scope of the CoinWidget constructor. That should be an easy fix - move their pointers into the header file i.e. define (I now tend to use my.. as a member prefix)
    Qt Code:
    1. protected:
    2. SoSeparator *myRoot;
    3. SoRotationXYZ *myRootRot;
    To copy to clipboard, switch view to plain text mode 

    and change the constructor to
    Qt Code:
    1. .
    2. myRoot = new SoSeparator;
    3. myRootRot = new SoRotationXYZ;
    4. .
    To copy to clipboard, switch view to plain text mode 
    Now you've got initialised objects available throughout your class. You should add a
    Qt Code:
    1. delete myRoot;
    2. delete myRootRot;
    To copy to clipboard, switch view to plain text mode 
    in the destructor. The next problem seems to be that you have never initialised the xRot variable. I think you can change the definition of xRot in the header to
    Qt Code:
    1. float xRot;
    To copy to clipboard, switch view to plain text mode 
    Now in the constructor change the code to
    Qt Code:
    1. .
    2. myRootRot = new SoRotationXYZ;
    3. xRot = 0.0f
    4. myRootRot->angle.setValue(xRot);
    5. myRoot->ref();
    6. myRoot->addChild(rootRot);
    7. myRoot->addChild(new SoCone);
    8. .
    To copy to clipboard, switch view to plain text mode 
    Thex setXRotation has something like
    Qt Code:
    1. if(a != xRot)
    2. {
    3. xRot = a;
    4. myRootRot->angle.setValue(xRot);
    5. }
    To copy to clipboard, switch view to plain text mode 
    The assert is likely to have been displayed because the SosFFloat was never initialised with a setValue - and I guess your still linking to a debug libary that has an internal reference to the original source code that you've now deleted. You might want to consider using an "SoRotation" instead later when you try to combine the other axes.

    Hope this helps

    Pete

  13. #12
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Thanks Pete/Marcel for the suggestions. Pete: you mentioned "move their pointers into the header file." Good idea, except I couldn't do this before because I needed to state

    Qt Code:
    1. SoQt::init(this);
    To copy to clipboard, switch view to plain text mode 

    before I could refer to any of the Coin classes (SoRotationXYZ, SoSFFloat, etc). But the SoQt::init() is in the CoinWidget constructor, so I couldn't refer to SoSFFloat in the coinwidget.h file. I've gotten around this now by creating a separate class, "Model," to hold all of my Coin geometry. These are my files:

    main.cpp
    window.h/.cpp (the Qt interface)
    coinwidget.h/.cpp (the Coin3d initialization)
    model.h/.cpp (the Coin3d geometry)

    My problem now, however: I declare a "coinWidget" object in my Window class, and then a "model" object in my "CoinWidget" class... but now I don't know how I can send signals from my Qt objects (i.e. "xSlider") to my "model" signals. (I haven't defined the signal/slot functions in my Model class yet; they're still in the CoinWidget class. I wanted to see if it's possible, first.)

    Should I, for example, go ahead and pass the signals from Window to CoinWidget as I'm doing now, then emit the signal again from CoinWidget to the Model class (after I set up the slots in the Model class, of course)?

    I apologize in advance: i'm going to post the program files, below. If it's innappropriate for me to do so, let me know Wysota.

    Qt Code:
    1. ++++++ main.cpp ++++++
    2. #include <QApplication>
    3.  
    4. #include "window.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. Window window;
    10. window.show();
    11. return app.exec();
    12. }
    13.  
    14. ++++++ window.h ++++++
    15. #ifndef WINDOW_H
    16. #define WINDOW_H
    17.  
    18. #include <QWidget>
    19.  
    20. class CoinWidget;
    21. class QSlider;
    22.  
    23. class Window : public QWidget
    24. {
    25. Q_OBJECT
    26.  
    27. public:
    28. Window();
    29.  
    30. private:
    31.  
    32. QSlider *createSlider();
    33.  
    34. CoinWidget *coinWidget;
    35. QSlider *xSlider;
    36.  
    37. };
    38.  
    39. #endif
    40.  
    41. ++++++ window.cpp ++++++
    42. #include <QtGui>
    43.  
    44. #include "coinwidget.h"
    45. #include "window.h"
    46.  
    47. Window::Window()
    48. {
    49. coinWidget = new CoinWidget;
    50.  
    51. xSlider = createSlider();
    52.  
    53. connect(xSlider, SIGNAL(valueChanged(int)), coinWidget, SLOT(setXRotation(int)));
    54. connect(coinWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
    55.  
    56. // NOTE: above is how I did it when I thought I could place the model in
    57. // the CoinWidget class. Now that I've a separate class, Model,
    58. // which contains the model, I don't know how I can pass SIGNALs to
    59. // a Model object without declaring the object here first... but which
    60. // doesn't make sense to do. I declare the "model" object in the
    61. // Coinwidget::Coinwidget() constructor. ...although, as I asked above:
    62. // perhaps I should leave this as it is, then forward the signal on to the
    63. // model class?
    64.  
    65. QHBoxLayout *mainLayout = new QHBoxLayout;
    66. mainLayout->addWidget(coinWidget);
    67. mainLayout->addWidget(xSlider);
    68. setLayout(mainLayout);
    69.  
    70. xSlider->setValue(12);
    71. setWindowTitle(tr("Hello COIN"));
    72. }
    73.  
    74. QSlider *Window::createSlider()
    75. {
    76. QSlider *slider = new QSlider(Qt::Vertical);
    77. slider->setRange(0, 360);
    78. slider->setSingleStep(36);
    79. slider->setPageStep(12);
    80. slider->setTickInterval(12);
    81. slider->setTickPosition(QSlider::TicksRight);
    82. return slider;
    83. }
    84.  
    85. ++++++ coinwidget.h ++++++
    86. #ifndef COINWIDGET_H
    87. #define COINWIDGET_H
    88.  
    89. #include <QMainWindow>
    90. #include <Inventor/Qt/SoQt.h>
    91.  
    92. class CoinWidget : public QMainWindow
    93. {
    94. Q_OBJECT
    95.  
    96. public:
    97. CoinWidget(QWidget *parent = 0);
    98. ~CoinWidget();
    99.  
    100. QSize minimumSizeHint() const;
    101. QSize sizeHint() const;
    102.  
    103. float deg2rad(int angle) { return (angle * 3.1416/180.00); }
    104.  
    105. public slots:
    106.  
    107. // refer to other comments
    108. void setXRotation(int angle);
    109.  
    110. signals:
    111.  
    112. // refer to other comments
    113. void xRotationChanged(int angle);
    114.  
    115. protected:
    116.  
    117.  
    118. private:
    119. void normalizeAngle(int *angle);
    120.  
    121. };
    122.  
    123. #endif
    124.  
    125. ++++++ coinwidget.cpp ++++++
    126. #include <QtGui>
    127. #include <QtCore>
    128.  
    129. #include <Inventor/Qt/SoQt.h>
    130. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    131.  
    132. #include "coinwidget.h"
    133. #include "model.h"
    134.  
    135.  
    136. CoinWidget::CoinWidget(QWidget *parent) : QMainWindow(parent)
    137. {
    138.  
    139. SoQt::init(this);
    140.  
    141. Model *model = new Model(this);
    142.  
    143. setCentralWidget(model->getWidget());
    144. model->setDefaultScene();
    145.  
    146. }
    147.  
    148. CoinWidget::~CoinWidget() {
    149.  
    150. // delete model; // : error C2065: 'model' : undeclared identifier
    151. // So I added "delete this;" in Model::~Model();
    152. // Is this the proper way to delete pointer/allocated memory
    153. // to the "model" object?
    154.  
    155. }
    156.  
    157. QSize CoinWidget::minimumSizeHint() const {
    158.  
    159. return QSize(200, 200);
    160.  
    161. }
    162.  
    163. QSize CoinWidget::sizeHint() const {
    164.  
    165. return QSize(400, 400);
    166.  
    167. }
    168.  
    169. void CoinWidget::setXRotation(int angle)
    170. {
    171.  
    172. // I was thinking that I should delete this member function, since this Class is set up
    173. // only to initialize the Coin3d window... but--again, as I asked above--maybe I should
    174. // keep it, and pass the signal again to the Model class. I realize, btw, that the
    175. // function doesn't do anything currently. I'll sort that out after I figure out how to
    176. // route the signals/slots.
    177.  
    178. float a = deg2rad(angle);
    179. qDebug("angle = %.4f", a);
    180. }
    181.  
    182. ++++++ model.h ++++++
    183. #ifndef MODEL_H
    184. #define MODEL_H
    185.  
    186. #include <Inventor/Qt/SoQt.h>
    187. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    188. #include <Inventor/nodes/SoSeparator.h>
    189. #include <Inventor/nodes/SoRotationXYZ.h>
    190. #include <Inventor/fields/SoSFFloat.h>
    191.  
    192. class Model : public SoQtExaminerViewer
    193. {
    194.  
    195. public:
    196.  
    197. Model( QWidget *parent = NULL, const char *name=NULL, const SbBool embed=TRUE);
    198. ~Model(void);
    199.  
    200. void setDefaultScene();
    201.  
    202. protected:
    203.  
    204. private:
    205.  
    206. SoSeparator *root;
    207. SoRotationXYZ *myRot;
    208. SoSFFloat xRot;
    209.  
    210. };
    211.  
    212. #endif
    213.  
    214. ++++++ model.cpp ++++++
    215. #include <Inventor/Qt/SoQt.h>
    216. #include <Inventor/nodes/SoSeparator.h>
    217. #include <Inventor/nodes/SoRotationXYZ.h>
    218. #include <Inventor/nodes/SoCone.h>
    219. #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
    220. //#include <Inventor/fields/SoSFFloat.h>
    221.  
    222.  
    223. #include <model.h>
    224.  
    225.  
    226. Model::Model( QWidget *parent, const char * name, const SbBool embed)
    227. : SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_ALL, SoQtViewer::BROWSER, TRUE) {
    228.  
    229. QWidget *widget = this->buildWidget(this->getParentWidget());
    230. this->setBaseWidget(widget);
    231. this->setDecoration(false);
    232. }
    233.  
    234.  
    235. Model::~Model() {
    236.  
    237. delete this;
    238.  
    239. /* FYI Pete:
    240. "You can not call delete on nodes [including SoSeparators, SoRotationXYZ, etc.]
    241. because the destructor is protected. Nodes are deleted when you call unref() on
    242. them and the reference count goes to zero. You must of course first ref() a node
    243. before you can unref() it." from a Coin3d developer
    244. */
    245. root->unref();
    246. myRot->unref(); //actually, I guess I shouldn't do this since I didn't "ref()" it.
    247.  
    248. }
    249.  
    250. void Model::setDefaultScene(void) {
    251.  
    252. root = new SoSeparator;
    253. root->ref();
    254. root->addChild(new SoCone);
    255.  
    256. this->setSceneGraph(root);
    257. this->show();
    258.  
    259. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vonCZ; 11th May 2007 at 12:01.

  14. #13
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    In case a simple visual will help, here it is. Again, the problem is I don't know how to connect the SIGNAL from the slider, to the cone rotation.
    Attached Images Attached Images

  15. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    I didn't look at the code yet, but the normal approach is to create wrappers in the classes that are liked to the signal and slot you want to connect.

    For example if class A contains object obj1 and class B contains object obj2, then to connect a signal from obj1 to a slot in obj2:
    obj1 signal -> class A slot -> class A signal -> class B slot -> obj2 slot.

    Of course, this has to be done from a class that hass access to both A and B.
    This you can do if you don't want to redesign too much.

    Regards

  16. #15
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    First I should say: it is no problem at all to do a complete redesign. I think there is a simple solution, on how to connect a Qt widget to Coin geometry/fields/etc, I just don't know how to do it yet. (I think I said this before: Qt is awesome, with all the sample code to figure out how to do things. Coin on the other hand: almost nothing, not even a simple demo to integrate Coin & Qt.)

    Do I understand you correctly: by "wrapper", do you mean create a new class that derives from both the Window and Model classes (the Qt widget and Coin geometry classes), and use functions from this class to access the Model fields? For example:

    given:
    qt _obj
    model_obj

    qt_obj signal -> WrapperClass slot -> function in WrapperClass updates field_value in model_obj (i.e. SoSFFloat xRot)

  17. #16
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    No, I said "wrapper functions" - signals and slots.

  18. #17
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    OK, Marcel, from what I gather you're talking standard SIGNALs and SLOTs stuff, right? So I need to be able to add SLOTs in my Model class.

    but: my Model class (in "model.cpp") doesn't (and cannot?) have any SLOTs, because it derives only from a Coin3d class, "SoQtExaminerViewer". I want to put fields/variables in my Model class that are updated by input from Window-class SIGNALs. What is the best way to add them?? I must include the Q_OBJECT macro and, presumably, derive my Model class not only from the SoQtExaminerViewer class, but also from a Qt class. Which class should I choose? ...or is this even the right path?

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coin3d + Qt

    Quote Originally Posted by vonCZ View Post
    I've posted this in the Newbie section without much luck yet; figured I'd try here.
    Please, don't post multiple threads on the same topic.

    Quote Originally Posted by vonCZ View Post
    but: my Model class (in "model.cpp") doesn't (and cannot?) have any SLOTs, because it derives only from a Coin3d class, "SoQtExaminerViewer".
    Then use multiple inheritance. Just note that, due moc limitations, QObject must be listed as the first super class.

  20. #19
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt

    Quote Originally Posted by jacek View Post
    Please, don't post multiple threads on the same topic.
    plz delete #18 above; it's confusing here twice.

  21. #20
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Here's a bit of a hackaround with your code.

    I've used the old setXRotation in the coinwidget as a wrapper for the model (now promoted to be a class member). Model now its own setXRotation(float angle), but this is just a standard method available to the proxy. The order of adding children to the root is important - think left to right - so
    Qt Code:
    1. root->addChild(myRot);
    2. root->addChild(new SoCone);
    To copy to clipboard, switch view to plain text mode 
    works but
    Qt Code:
    1. root->addChild(new SoCone);
    2. root->addChild(myRot);
    To copy to clipboard, switch view to plain text mode 
    appears not to as the cone is now left of the rotation. Anyway the attached zip file was working for me. But remember that this technique is rotating the objects in "world space" - not just rotating the camera postion around the scene.

    Pete
    Attached Files Attached Files

  22. The following user says thank you to pdolbey for this useful post:

    vonCZ (12th May 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.