Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Something about listener...
QtWS25 Last Chance

[solved] Something about listener...

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 6.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Dear Qters...
    Hi,... I need many suggestion and help. A friend who built an application using Java suggest me a method, I am using Qt. He suggest me about listeners, like this
    " You need to register your code as a listener so that when a laser event happens, it tells your listener to handle it "
    What is listener in Qt? or may be there is another opinion...
    Thank you in advance,
    romeo-

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Listener is a Java concept.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        Still do not understand...Can we make it in Qt?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Sure, you can do almost everything with Qt. The question is - what do you want to do? In your post you have said "when a laser event happens" - I assume this is some device you have connected to your machine? Or is it a laser pointer and you detect it with a camera? There are just too many possibilities to answer your question without more info.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            What you are refering to is the Observer pattern. Google for it, or better yet, get yourself a copy of the book Design Patterns, Elements of Reusable Object-Oriented Software by E. Gamma et.al. (a.k.a. the Gang of Four or 'GoF').

            Can you do that with C++ and Qt? Absolutely. Do you want to? Depends... If you are using Qt throughout your application, I'd probably stick with signals & slots instead.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              [quote author="sierdzio" date="1341381788"]Listener is a Java concept.[/quote]

              Listener (AKA Observer) is not a java concept, it's a design pattern which is build in in Java :-)

              "See here on wikipedia":http://en.wikipedia.org/wiki/Observer_pattern

              The description in "GOF4":http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1341383858&sr=8-1&keywords=design+patterns (Design pattern by Erich Gamma and friends) is also very good

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • R Offline
                R Offline
                romeo.rbw
                wrote on last edited by
                #7

                Sorry for my lack of information, actually laser is a spot light from laser pointer. I got the x,y coordinate of this spotlight. I want to make some event for replacing a mouse action, such as: laser ON, laser OFF, laser enter an area, laser leaving an area, etc. Are there any suggestion for those from a scratch in Qt, so I hope I can make some application after that. Thanks in advance.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  I would use signal/slot as Andre suggested. It's the typical way to do such things in Qt and it is in fact something like the obeserver :-)

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    [quote author="Gerolf" date="1341383882"][quote author="sierdzio" date="1341381788"]Listener is a Java concept.[/quote]

                    Listener (AKA Observer) is not a java concept, it's a design pattern which is build in in Java :-)

                    "See here on wikipedia":http://en.wikipedia.org/wiki/Observer_pattern

                    The description in "GOF4":http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1341383858&sr=8-1&keywords=design+patterns (Design pattern by Erich Gamma and friends) is also very good[/quote]

                    Well, true. Bad choice of words on my part, made mostly to keep it short. Sorry! :)

                    (Z(:^

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      David_Gil
                      wrote on last edited by
                      #10

                      bq. I want to make some event for replacing a mouse action, such as: laser ON, laser OFF, laser enter an area, laser leaving an area, etc. Are there any suggestion for those from a scratch in Qt, so I hope I can make some application after that. Thanks in advance.

                      From what you're saying ("make some event for replacing a mouse action") maybe (just maybe) it's better to handle it with events ("QEvent":http://qt-project.org/doc/qt-4.8/QEvent.html).

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #11

                        [quote author="David_Gil" date="1341389798"]bq. I want to make some event for replacing a mouse action, such as: laser ON, laser OFF, laser enter an area, laser leaving an area, etc. Are there any suggestion for those from a scratch in Qt, so I hope I can make some application after that. Thanks in advance.

                        From what you're saying ("make some event for replacing a mouse action") maybe (just maybe) it's better to handle it with events ("QEvent":http://qt-project.org/doc/qt-4.8/QEvent.html).
                        [/quote]

                        But events are no listener / observer pattern. And events are typically not for inter object communication with loose coupling. For events, both must know the event.

                        The event can be the solution for synchronizing things to the event loop, but for the observer, it would be signal/slot for me.

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          romeo.rbw
                          wrote on last edited by
                          #12

                          Thank you for every suggestion, I found in QEvent type manual:

                          QEvent::Enter --- Mouse enters widget's boundaries.
                          QEvent::DragEnter --- The cursor enters a widget during a drag and drop operation (QDragEnterEvent).
                          QEvent::DragLeave --- The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).

                          May be

                          • after the observer (signal-slot) recognize the area where the spotlight is, I can use QEvent like above, and

                          • using signal-slot to trigger the timer event to count how long a spotlight stay in one location for recognizing the click action,

                          • the spotlight can replace the mouse cursor using 'setpos' operation.

                          I need some suggestion about that, many thanks...

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            If you want it work like a mouse, you might try sending self-created mouse events to the widget...

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              romeo.rbw
                              wrote on last edited by
                              #14

                              Thanks Mr Andre, from your idea and I combine it with the chapter 6 of the Foundations of Qt Development by J.Thelin from Apress book, now I have the description of my program structure. Many thanks.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                I am sorry, but I am not familiar with that book, and I don't have time to go searching for it and read the chapter you reference.

                                1 Reply Last reply
                                0
                                • sierdzioS Offline
                                  sierdzioS Offline
                                  sierdzio
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  Andre, he is not asking you to read it, so don't worry too much :)

                                  (Z(:^

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    andre
                                    wrote on last edited by
                                    #17

                                    You're right, actually. It was a statement, not a question.

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved