PDA

View Full Version : problem with "connect" signal/slot



rimie23
5th June 2012, 21:35
Hi
i have class QOgrerenderwindow


void QOgreRenderWindow::mousePressEvent(QMouseEvent* evt)
{
if (evt->buttons() & Qt::MiddleButton)
mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
else
emit mousePress(evt);
}
void QOgreRenderWindow::wheelEvent(QWheelEvent * evt)
{
Ogre::Real valueZoom;

if(evt->delta() < 0)
valueZoom = 1;
else if(evt->delta() > 0)
valueZoom = -1;

mCamera->moveRelative(Ogre::Vector3(0, 0, valueZoom/* * dist*/));

emit wheel(evt);
}

and in Qogrewidget i have



connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mouseP ress(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mous eRelease(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMo ve(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWhee lEvent*)));
void QOgreWidget::mousePress(QMouseEvent* evt)
{
Q_UNUSED(evt);
std::cout << sender()->objectName().toStdString() << " mousePress" << std::endl;
}
void QOgreWidget::wheel(QWheelEvent * evt)
{
Q_UNUSED(evt);
std::cout << sender()->objectName().toStdString() << " wheel" << std::endl;
}


the problem is when i debug it enter to wheel function only
even when i clic with mouse it dos not enter to mousepress
have you an idea why ?

amleto
6th June 2012, 01:01
show complete compilable example yadda yadda.

since it works for mouse wheel you have probably made a very simple mistake somewhere.

Have you checked console output to check that the connection is made successfully?
Is mousePress actually a slot?
Do you connect mousePress at the same place as wheel ?

All of these questions would be answered already if you would provide complete, compilable examples, instead of doing what you always do and post code fragments with no context.


This code


connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mouseP ress(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mous eRelease(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMo ve(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWhee lEvent*)));
is meaningless - you don't even show what method it belongs to!

COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES COMPLETE COMPILABLE EXAMPLES

wysota
6th June 2012, 01:11
I can only say that it is very unusual to try to pass event objects through signals to foreign slots.

rimie23
6th June 2012, 10:33
complete compilable example
yes i know that i must give you complete compilable exemple
and i know if i give you that you can help me
BUT
i tried to think an exemple like mine and withoute ogre i do not found an idea how i do it

Have you checked console output to check that the connection is made successfully?
yes , when i clic with mouse i do not see "mouse pressed" but if i execute run wheel i see " wheel"

Is mousePress actually a slot?
yes

Do you connect mousePress at the same place as wheel ?
yes

look that is my code in qogrerender and qogrewidget (it is complete code but with ogre )
7805780678077808



and thanks to accept help me


EDIT

I can only say that it is very unusual to try to pass event objects through signals to foreign slots.
yes i know that is not normal
look at this post it will explain to you why i use 2 clases
http://www.qtcentre.org/threads/49152-put-widget-in-layout?p=220802&highlight=#post220802

i choose the secon advice of ChrisW67

You have 13 Ogre widgets sharing the same Ogre scene. One widget is the left half and the other 12 are in the grid. Put each Ogre widget inside the group boxes you already have. (Actually it could all be a single QGridLayout but you need to walk before running)
i subdevice ogrewidget on twoo class : qogrerenderwindow and qogrewidget

i create my object in "qogrewidget" BUT i render theme in "qogrerenderwindow" to render them i use camera for that i put mousepresseeven in "qogrerenderwindow" and because
the objects rendred are in oogrewidget class i need to make mousepress too

for that i make this melange

StrikeByte
6th June 2012, 11:00
Did you check if the event gets triggered? (qDebug :P)

Added after 7 minutes:

in the code box on the forum you use this code:


if (evt->buttons() & Qt::MiddleButton) //you filter out the middle mouse button (no signal will be emitted)
mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
else
emit mousePress(evt);

in the attachment you use this code:


if (evt->button() == Qt::LeftButton) //here you filter the left mouse button (no signal will be emitted)
mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
else
emit mousePress(evt);


what mouse button are you clicking and expecting an emit?

wysota
6th June 2012, 11:08
yes i know that is not normal
look at this post it will explain to you why i use 2 clases
http://www.qtcentre.org/threads/49152-put-widget-in-layout?p=220802&highlight=#post220802

i choose the secon advice of ChrisW67

i subdevice ogrewidget on twoo class : qogrerenderwindow and qogrewidget

i create my object in "qogrewidget" BUT i render theme in "qogrerenderwindow" to render them i use camera for that i put mousepresseeven in "qogrerenderwindow" and because
the objects rendred are in oogrewidget class i need to make mousepress too

for that i make this melange

I don't care that you use multiple widgets. This doesn't explain why you are doing weird things with the event system. Maybe if you tell us what you are trying to achieve, we'll find a better solution.

rimie23
6th June 2012, 11:11
i just change the code in attachement because the first code did not work i tried to change it

what mouse button are you clicking and expecting an emit?
what you mean

if (evt->buttons() & Qt::MiddleButton) //you filter out the middle mouse button (no signal will be emitted)
why ? but why enter to weheel and not at the press

what you propose?


EDIT
when i run my program i see this
7810

my main objectif is when i clic on the big groupbox (big widget) i add an object(and see it in the others )

i created the widget (smalls and big ) in the class "Qogrewidget" and to render the scene in it i apply qogrerenderwidow like that(all that is in the attachement)


void QOgreWidget::setViewNum(int num)
{


--------------------------------------------------------------

if(num == 1)
{

QWidget *central = new QGroupBox("My Scene", this);
float wi=central->width();
float hi=central->height();
QOgreRenderWindow * orw = new QOgreRenderWindow(QString("View2"),mSceneMgr,mRoot,nb_cam,/*central*/wi,hi);

QHBoxLayout* Layout = new QHBoxLayout();
Layout->addWidget(orw);

central->setLayout(Layout);

mVerticalLayout->addWidget(central);

}
---------------------------------
for(int i = 0;i<mQOgreRenderWindowList.count();i++)
{
connect(mQOgreRenderWindowList[i],SIGNAL(keyPress(QKeyEvent*)),this,SLOT(keyPress(Q KeyEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(keyRelease(QKeyEvent*)),this,SLOT(keyRelea se(QKeyEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mouseP ress(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mous eRelease(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMo ve(QMouseEvent*)));
connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWhee lEvent*)));
}

it work with wheel when i make the curseur of mouse on widget i see that the camera change it position

Now i use
mousepresseevent in qogrerenderwindow : because in this class i create my camera and when i click with mouse i need camera
i use mousepress in qogrewidget : because i clic on this widget and my objects are created in this class

I did not found another idea to do what i want
Now , to add object by cliking with mouse i tried firstly to use simple "mousePressEvent(QKeyEvent* evt)"
it dos not enter to it

StrikeByte
6th June 2012, 11:18
I'll use this code as example


if (evt->button() == Qt::LeftButton) //here you filter the left mouse button (no signal will be emitted)
mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
else
emit mousePress(evt);

in this code if you click the left mouse button the signal mousePress won't be emitted.


and did you check if the mouseEvent (not the slot) is triggered when you click a mousebutton?



void QOgreRenderWindow::mousePressEvent(QMouseEvent* evt)
{
qDebug() << "YEA event works!";
if (evt->buttons() & Qt::MiddleButton)
mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
else
emit mousePress(evt);
}



maybe an alternative to the signal/slot, is installing an eventFilter see eventsandfilters

rimie23
6th June 2012, 11:33
@StrikeByte: i tried it it does not enter to it

wysota
6th June 2012, 11:34
So you mean you have 12 small widgets that should display the same data as the big widget? Are you doing that by adding same objects to those small widgets as you add to the big one? Isn't it simpler to make all of them share the same data instead of doing all the crazy stuff with events?

rimie23
6th June 2012, 12:09
So you mean you have 12 small widgets that should display the same data as the big widget?
Yes, But each widget display the same data with by the uses of defferent camera (widget1with camera1,widget2with camera2...............)

Isn't it simpler to make all of them share the same data instead of doing all the crazy stuff with events?
i tried to make that but it dos not work
the only idea that work is this

StrikeByte
6th June 2012, 12:12
If all the small widgets have the same object, but different views (camera's), why does the main window need to know if you clicked at one?
Is it to show the small widget in the big widget with the same view as the smaler one?


Is it possible to attach the entire project, so i can take a look at it after work?

rimie23
6th June 2012, 12:16
yes , i will be very hapyy if you can help me
But it is with ogre
( i will upload all the project)

StrikeByte
6th June 2012, 12:18
Thats not a problem i've tested ogre once
i can reinstall the lib so i can test it

rimie23
6th June 2012, 12:36
OK
i will upload it (all the projcet with files and dll)in website and i will put the link her

wysota
6th June 2012, 13:34
i tried to make that but it dos not work
So make it work :)


the only idea that work is this
Don't be offended but that's not the brightest approach. You are duplicating data and effectively spending much effort on synchronizing your scenes instead of focusing on the real task.

A trivial approach to solving your problem is having a single controller object, notifying all other objects upon changes in the scene. Then you can do your duplication based on high-level definition of things that happen around. So instead of transmitting "canvas x was clicked in position a,b" you can transmit "object A has been created at coordinates x,y,z". Then each "view" can query the "scene" for the object and create its local incarnation of it. Right now since all "views" can have different transformations, you'll spend lots and lots of time trying to recalculate coordinates from all other views based on their projections.

rimie23
6th June 2012, 13:52
Then you can do your duplication based on high-level definition of things that happen around
i don't understand what you mean her

So instead of transmitting "canvas x was clicked in position a,b" you can transmit "object A has been created at coordinates x,y,z". Then each "view" can query the "scene" for the object and create its local incarnation of it. Right now since all "views" can have different transformations, you'll spend lots and lots of time trying to recalculate coordinates from all other views based on their projections.

i do not understand very good the idea

and i do not know if i can do that in ogre or no

wysota
6th June 2012, 14:52
i don't understand what you mean her
I mean that you shouldn't care what was clicked where but rather what happened as a result of that click.


and i do not know if i can do that in ogre or no
OGRE has nothing to do with this. You'd only use OGRE inside the view, the scene would be composed of pure C++/Qt functionality. So yes, you can do that with OGRE. I'm not saying that's the best approach (having some kind of scene-view separation inside OGRE would be better) but it's definitely better than what you are doing now. If you still do not understand what I mean, read about the "model-view-controller" design pattern (just don't look at english wikipedia article on it, as the article is very poor).

rimie23
6th June 2012, 15:23
the scene would be composed of pure C++/Qt functionality.
no i use functionality of ogre to create scene (the scene is created in ogre ) and renderd using ogre camera ,functionality of ogre too
and in window of ogre the window of ogre we put than the window of ogre in widdget

EDIT
in the first time when i was just one class i can display many view as i want using thiss function


void OgreWidget::createViewports(void)
{
mWindow->addViewport(mCamera, 0, 0, 0, 0.5, 1); // large left half viewport
int columns = 3;
int rows = 4;
for(int y = 0; y < rows; y++)
for(int x = 0; x < columns; x++)
{
mWindow->addViewport(mCamera,
x + y * columns + 1, // each viewport needs a unique zorder value
0.5f + (0.5f / columns) * x, // left edge
(1.0f / rows) * y, // top edge
0.5f / columns, // tile width
1.0f / rows); // tile height
}
}

you can see that to render we use mwindow : it is ogre window , we render on it and put the result in widget
i change this idea because i can't put the sub-view in widgets indepedent on the the big widget(or big view)
when i write

setCentralWidget(ogrewidget) it show to me all the view in one widget

that's why i use the new idea

and that's why i afraid that your idea do not work in ogre because we use the same window of ogre

wysota
6th June 2012, 15:41
no i use functionality of ogre to create scene (the scene is created in ogre ) and renderd using ogre camera ,functionality of ogre too
I don't think you understand.

rimie23
6th June 2012, 15:49
I don't think you understand.
what you mean then?
i think that you mean :
1 my object is created in c++ or in qt (opengl) i said to you no, they are created with ogre

Edit
i am sure we can't impliment it because i apps all this mouth with only this problem "how i make each view "
if you want i give you ogre (you jst coppy and collé it) and my first project (with the single class it very easy to understand ) to more understand why we can't applicate your idea :)

that's the files.cpp of my first project to see in the code why we can't impliment your idea (if you want i upload too the file.h)
78127811


i hope too that your idea is applicable because if it is i will so huppy i will not refer all my project (because i do not want that)

wysota
6th June 2012, 16:27
i am sure we can't impliment it
I am sure you can, especially after looking here: http://www.ogre3d.org/docs/manual/manual_4.html#SEC4


if you want i give you ogre (you jst coppy and collé it) and my first project (with the single class it very easy to understand ) to more understand why we can't applicate your idea :)
I don't need your project. You are so focused on the fact that you use OGRE that you fail to see the big picture of what you are doing.

rimie23
6th June 2012, 16:51
Ok maybe i did not understand good your idea

Now, i have project that work very well with one widget , (he is in the attachment ,there are many other widgets they are not used)

if you can exemplain to me how i exploit your idea in my project
as i said i will so huppy if that work i will not loss many of time ,

wysota
6th June 2012, 18:09
Learn about model-view-controller pattern. There is nothing more for me to explain if you understand and employ this pattern.