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...
Forum Updated to NodeBB v4.3 + New Features

[solved] Something about listener...

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 7.1k Views 1 Watching
  • 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.
  • 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