Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: Coin3d + Qt: SIGLNALs and SLOTs

  1. #21
    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!

  2. #22
    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!

  3. #23
    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

  4. #24
    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

  5. #25
    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,

    Sorry but I'm at work athe moment so I can't give you a "tested" response, but I can give you something to work on during the day. I can break your problem into two peices

    1. How do I connect the signals and slots.
    2. How do I share a scenegraph.

    The first is relatively straightforward - I'll outline 3 options, but for now I'd recommend the first as it should be the easiest to implement and test.

    a) Alter your Window2 constructor to take a Window pointer, and cache it in a Window2 member variable - perhaps call it "partnerWindow". From the top down in main.cpp you'd see something like
    Qt Code:
    1. Window *window = new Window();
    2. Window2 *window2 = new Window2(window);
    3. window->show();
    4. window2->show();
    To copy to clipboard, switch view to plain text mode 
    Now you can connect public slots and signals between the two windows in your Window2 constructor - or another method.

    b) Connect the signals and slots statically in main.cpp with fully qualified QObject::connect(.....) methods - you have pointers to both objects here.

    c) Build a new proxy "controller" class and use this to sychronise events between the 2 windows.

    The next piece needs some testing, but in essence what you can do is to expose the scenegraph root node in window.cpp/h via a public getSceneGraph() function. In option a) this can be accessed directly from the new classmember (partnerWindow) - in options c) and b) you might need a corresponding setSceneGraph(...) exposed in Window2. Both set/getSceneGraph will actually need to be wrappers for the enclosed Model objects which will also need amending . Now you should be able to set the Window's Model scenegraph as the root node of the Model in Window2 - what happens next I can't tell. I'll try it myself tonight.

    You can post the code to "peter at dolbey dot freeserve dot co dot uk" - with the usual replacements.

    Pete
    Last edited by pdolbey; 22nd May 2007 at 09:28.

  6. #26
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Coin3d + Qt: SIGLNALs and SLOTs

    Hi pdolbey,

    I am trying to learn how to embed a coin widget inside a qt display and found your post very helpful. Could you post your .ui file so that I can open and manipulate inside qt designer?

    Thanks a lot.

    J. Wieland

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

    I don't use Designer, so don't follow the threads too closely on how to integrate Coin and Qt on designer (i'm refering to the threads on the Coin list; there aren't any here, far as I can tell.)


    But my understanding is: You cannot use SoQtExaminerViewer (or the other SoQt viewer/renderArea classes) with Designer, and therefore pDolbey or anyone else with a Coin3d+SoQt* project won't have a .ui file. On the other hand: Coin3d came out with Quarter recently, which does enable you to use Designer to build your Qt/Coin3d apps. But again: I haven't used this (Quarter), either. Nevertheless: "quarter" is what you're looking for if you want to build your apps with Designer. I think.
    Last edited by vonCZ; 15th May 2009 at 07:58.

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.