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

Thread: Coin3d + Qt: SIGLNALs and SLOTs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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
    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.

  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

    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.

  17. #16
    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

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

    vonCZ (12th May 2007)

  19. #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

    Quote Originally Posted by pdolbey View Post
    I've used the old setXRotation in the coinwidget as a wrapper for the model (now promoted to be a class member).
    BEAUTIFUL!! Thanks a million, Pete!

  20. #18
    Join Date
    May 2007
    Location
    Athens, Greece
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Following the very useful examples, and after having hours of conversation with vonCZ, I managed to use the proposed solutions for my -similar- project... Now, here's my problem.

    ***Please note that I am absolutely new to Qt, Coin, and C++, so probably the answer might be something really obvious, but not to me!***

    So, I managed to have window.h/window.cpp, model.h/model.cpp, and coinwidget.h/coinwidget.cpp working. What I am trying to do now, is have one more window with the coin screen. Here's why; I want to have the (initial) window with some control features i added (couple of spinboxes etc) and the second window (which I create with window2.h/window2.cpp) to have the coin model and a couple of widgets. BUT, with what I've written I get two instances of coinwidget, therefore all my signals from window.cpp spinboxes do not have any effect to my window2 coin model. To make it more clear: I need to use the window.cpp coinwidget instance in my window2.cpp.

    I am certain the answer is clear to someone with OOP experience, I do suspect that it has something to do with declaring public classes and instances, but still don't know how to get around....

    Here's a bit of my code (I shouldn't post the whole thing since it's going to be long)...

    main.cpp

    the same as in the previous post, only changes are:

    Window *window = new Window();
    Window2 *window2 = new Window2();
    window->show();
    window2->show();

    window.h

    Only change is transferring "CoinWidget *coinWidget;" from the private: to the public:

    window2.h

    #ifndef WINDOW2_H
    #define WINDOW2_H

    #include <QWidget>
    #include "window.h"
    class CoinWidget;
    class QSlider;
    class QDial;

    class Window2 : public QWidget
    {
    Q_OBJECT

    public:
    Window2();

    public slots:

    private:

    QSlider *xSlider;
    QDial *J2Dial;
    };
    #endif

    window2.cpp

    #include <QtGui>
    #include "coinwidget.h"
    #include "window2.h"
    #include "window.h"

    Window2::Window2()
    {
    xSlider = new QSlider;
    J2Dial = new QDial;
    QGridLayout *mainLayout2 = new QGridLayout;
    //mainLayout2->addWidget(coinWidget); <-- This is the part not working
    mainLayout2->addWidget(xSlider);
    setLayout(mainLayout2);
    xSlider->setValue(0);
    xSlider->setRange(0,360);
    J2Dial->setRange(-125,125);
    J2Dial->setNotchesVisible(1);
    J2Dial->setNotchTarget(5.0);
    J2Dial->setSingleStep(1.0);
    }

    No changes were made to model.h, model.cpp, coinwidget.h, coinwidget.cpp (ok, there are changes but are not related to the problem-honestly!).

    Any help will be greatly appreciated, thanks in advance.

    X-man

    PS. Sorry for the long post!

  21. #19
    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

    X-man,

    I did see your post earlier, but my first reply got scewed up by a timeout.

    Its not too hard to get references from one window to another. However what I think your trying to do is display the same widget in two containers - and I don't really think thats very sensible. In the windows world your widget will eventually map to a HWND which is unique to a window.

    My original mods for vonCZ were based on making his existing code work with as small changes as possible. Theres are a number of considerations.

    1. The Model class manages both a Coin viewer and its scenegraph - this should really have been split into 2 separate classes.
    2. The coinwidget interacts with a rotation node in the scenegraph. This effectively changes the rotation of the code in world space, not the position of the camera.

    I'd like to get a better understanding of what your tying to achieve, perhaps some screen mock-ups, before making any further suggestions. I would still always ask the core question as well - "Why are you trying to do it this way?".

    Pete

  22. #20
    Join Date
    May 2007
    Location
    Athens, Greece
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Pete,

    first of all, thanks for the reply. Now, regarding your points...

    1. It make sense; i mean, having them in separate classes - but that should not be a problem for the time being (or is it? if so, any advice on how to change that->creating two classes?)
    2. No problem with that - I now have six (6) spinboxes inside my window.cpp, who alter six rotation nodes inside my model. As for them rotating in real world (not camera), that's exactly what I want them to do.

    Ok, now on to your "why-are-you-doing-that" question...

    From what I understood in your example (correct me if I'm wrong), the application shows a window (created in window.cpp), which includes some widgets (a slider in your case, some spinboxes in mine), one of the widgets being coinwidget, which then (through the coinwidget.cpp) creates a -coin- model, which is also shown (since we have a "show();" near the end of model.cpp).

    Where I want to get - one window with my spinboxes alone, which communicate via slots/signals with certain rotation nodes of the model (via the coinwidget), in order to rotate my model. And then, another window with that model and ALSO a couple of Qt widgets (I'm not sure yet what kind of widgets I will be needing, but lets take for example that I will need some QLCDNumber widgets).

    And here's the problem; in order to connect the spinboxes in window.cpp (the same way you connected the slider), I create a coinwidget = new coinwidget. Just in order to do the slot/signal thing (let's say that I don't even include the "mainLayout->addWidget (coinWidget);" part). So, at that point we have a coinwidget created, with certain rotations altered "dynamically" from some widgets inside the window.cpp, and all these changes can be seen in the created model (because of the "show()" in model.cpp). Now, if I want in my window2.cpp to have that same model shown at (0,0) and have my other widgets (the lcdnumbers) underneath, I don't know how to call that instance. Naturally, if I just go with "addWidget (coinWidget);", it returns that it is undeclared, if I have a "coinwidget2 = new Coinwidget" before, I get a model shown, but it's just a new instance, so any changes I make in my spinboxes, are not trasmitted inside this model. I also tried something like "addWidget (Window::coinWidget)", but I got "illegal reference to non-static member 'Window::coinWidget'" in return.

    Am I going the wrong way here? I'm open to any suggestions, either in terms of general approach or in specific coding instructions.

    Let me know if you need the whole of my code to check it out - i'll .rar it and pass it on.

    Thanks again for your attention, I appreciate it .

    X-man

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
  •  
Qt is a trademark of The Qt Company.