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

Thread: problem with "connect" signal/slot

  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with "connect" signal/slot

    Hi
    i have class QOgrerenderwindow
    Qt Code:
    1. void QOgreRenderWindow::mousePressEvent(QMouseEvent* evt)
    2. {
    3. if (evt->buttons() & Qt::MiddleButton)
    4. mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
    5. else
    6. emit mousePress(evt);
    7. }
    8. void QOgreRenderWindow::wheelEvent(QWheelEvent * evt)
    9. {
    10. Ogre::Real valueZoom;
    11.  
    12. if(evt->delta() < 0)
    13. valueZoom = 1;
    14. else if(evt->delta() > 0)
    15. valueZoom = -1;
    16.  
    17. mCamera->moveRelative(Ogre::Vector3(0, 0, valueZoom/* * dist*/));
    18.  
    19. emit wheel(evt);
    20. }
    To copy to clipboard, switch view to plain text mode 
    and in Qogrewidget i have
    Qt Code:
    1. connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mousePress(QMouseEvent*)));
    2. connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mouseRelease(QMouseEvent*)));
    3. connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMove(QMouseEvent*)));
    4. connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWheelEvent*)));
    5. void QOgreWidget::mousePress(QMouseEvent* evt)
    6. {
    7. Q_UNUSED(evt);
    8. std::cout << sender()->objectName().toStdString() << " mousePress" << std::endl;
    9. }
    10. void QOgreWidget::wheel(QWheelEvent * evt)
    11. {
    12. Q_UNUSED(evt);
    13. std::cout << sender()->objectName().toStdString() << " wheel" << std::endl;
    14. }
    To copy to clipboard, switch view to plain text mode 
    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 ?
    Last edited by rimie23; 5th June 2012 at 21:46.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    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
    Qt Code:
    1. connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mousePress(QMouseEvent*)));
    2. connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mouseRelease(QMouseEvent*)));
    3. connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMove(QMouseEvent*)));
    4. connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWheelEvent*)));
    To copy to clipboard, switch view to plain text mode 
    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
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  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: problem with "connect" signal/slot

    I can only say that it is very unusual to try to pass event objects through signals to foreign slots.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    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 )
    QOgreRenderWindow.hQOgreWidget.hQOgreRenderWindow.cppQOgreWidget.cpp



    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/4915...ht=#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
    Last edited by rimie23; 6th June 2012 at 10:54.

  5. #5
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with "connect" signal/slot

    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:
    Qt Code:
    1. if (evt->buttons() & Qt::MiddleButton) //you filter out the middle mouse button (no signal will be emitted)
    2. mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
    3. else
    4. emit mousePress(evt);
    To copy to clipboard, switch view to plain text mode 

    in the attachment you use this code:
    Qt Code:
    1. if (evt->button() == Qt::LeftButton) //here you filter the left mouse button (no signal will be emitted)
    2. mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
    3. else
    4. emit mousePress(evt);
    To copy to clipboard, switch view to plain text mode 

    what mouse button are you clicking and expecting an emit?
    Last edited by StrikeByte; 6th June 2012 at 11:00.

  6. #6
    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: problem with "connect" signal/slot

    Quote Originally Posted by rimie23 View Post
    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/4915...ht=#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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    i just change the code in attachement because the first code did not work i tried to change it
    Qt Code:
    1. what mouse button are you clicking and expecting an emit?
    To copy to clipboard, switch view to plain text mode 
    what you mean
    Qt Code:
    1. if (evt->buttons() & Qt::MiddleButton) //you filter out the middle mouse button (no signal will be emitted)
    To copy to clipboard, switch view to plain text mode 
    why ? but why enter to weheel and not at the press

    what you propose?


    EDIT
    when i run my program i see this
    interfacee.jpg

    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)
    Qt Code:
    1. void QOgreWidget::setViewNum(int num)
    2. {
    3.  
    4.  
    5. --------------------------------------------------------------
    6.  
    7. if(num == 1)
    8. {
    9.  
    10. QWidget *central = new QGroupBox("My Scene", this);
    11. float wi=central->width();
    12. float hi=central->height();
    13. QOgreRenderWindow * orw = new QOgreRenderWindow(QString("View2"),mSceneMgr,mRoot,nb_cam,/*central*/wi,hi);
    14.  
    15. QHBoxLayout* Layout = new QHBoxLayout();
    16. Layout->addWidget(orw);
    17.  
    18. central->setLayout(Layout);
    19.  
    20. mVerticalLayout->addWidget(central);
    21.  
    22. }
    23. ---------------------------------
    24. for(int i = 0;i<mQOgreRenderWindowList.count();i++)
    25. {
    26. connect(mQOgreRenderWindowList[i],SIGNAL(keyPress(QKeyEvent*)),this,SLOT(keyPress(QKeyEvent*)));
    27. connect(mQOgreRenderWindowList[i],SIGNAL(keyRelease(QKeyEvent*)),this,SLOT(keyRelease(QKeyEvent*)));
    28. connect(mQOgreRenderWindowList[i],SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mousePress(QMouseEvent*)));
    29. connect(mQOgreRenderWindowList[i],SIGNAL(mouseRelease(QMouseEvent*)),this,SLOT(mouseRelease(QMouseEvent*)));
    30. connect(mQOgreRenderWindowList[i],SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMove(QMouseEvent*)));
    31. connect(mQOgreRenderWindowList[i],SIGNAL(wheel(QWheelEvent*)),this,SLOT(wheel(QWheelEvent*)));
    32. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by rimie23; 6th June 2012 at 11:37.

  8. #8
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with "connect" signal/slot

    I'll use this code as example
    Qt Code:
    1. if (evt->button() == Qt::LeftButton) //here you filter the left mouse button (no signal will be emitted)
    2. mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
    3. else
    4. emit mousePress(evt);
    To copy to clipboard, switch view to plain text mode 
    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?

    Qt Code:
    1. void QOgreRenderWindow::mousePressEvent(QMouseEvent* evt)
    2. {
    3. qDebug() << "YEA event works!";
    4. if (evt->buttons() & Qt::MiddleButton)
    5. mousePressStartPoint = Ogre::Vector2((float)evt->pos().x() / mVp->getActualWidth(),(float)evt->pos().y() / mVp->getActualHeight());
    6. else
    7. emit mousePress(evt);
    8. }
    To copy to clipboard, switch view to plain text mode 


    maybe an alternative to the signal/slot, is installing an eventFilter see http://doc.qt.io/qt-4.8/eventsandfilters
    Last edited by StrikeByte; 6th June 2012 at 11:31.

  9. #9
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    @StrikeByte: i tried it it does not enter to it

  10. #10
    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: problem with "connect" signal/slot

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    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

  12. #12
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with "connect" signal/slot

    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?

  13. #13
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    yes , i will be very hapyy if you can help me
    But it is with ogre
    ( i will upload all the project)

  14. #14
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with "connect" signal/slot

    Thats not a problem i've tested ogre once
    i can reinstall the lib so i can test it

  15. #15
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    OK
    i will upload it (all the projcet with files and dll)in website and i will put the link her

  16. #16
    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: problem with "connect" signal/slot

    Quote Originally Posted by rimie23 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    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

  18. #18
    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: problem with "connect" signal/slot

    Quote Originally Posted by rimie23 View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "connect" signal/slot

    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
    Qt Code:
    1. void OgreWidget::createViewports(void)
    2. {
    3. mWindow->addViewport(mCamera, 0, 0, 0, 0.5, 1); // large left half viewport
    4. int columns = 3;
    5. int rows = 4;
    6. for(int y = 0; y < rows; y++)
    7. for(int x = 0; x < columns; x++)
    8. {
    9. mWindow->addViewport(mCamera,
    10. x + y * columns + 1, // each viewport needs a unique zorder value
    11. 0.5f + (0.5f / columns) * x, // left edge
    12. (1.0f / rows) * y, // top edge
    13. 0.5f / columns, // tile width
    14. 1.0f / rows); // tile height
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. setCentralWidget(ogrewidget)
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by rimie23; 6th June 2012 at 15:29.

  20. #20
    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: problem with "connect" signal/slot

    Quote Originally Posted by rimie23 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Can"t connect signal and slot
    By Bennieboj in forum Newbie
    Replies: 6
    Last Post: 16th November 2011, 09:49
  2. debugging "signal does not reach slot" in a template class
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2010, 16:03
  3. Replies: 1
    Last Post: 23rd August 2008, 22:09
  4. QObject::connect says "no such signal"
    By MistaPain in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2006, 05:40

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.