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. Creating events instead of signals/slots

Creating events instead of signals/slots

Scheduled Pinned Locked Moved General and Desktop
30 Posts 4 Posters 14.8k 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
    Revu
    wrote on last edited by
    #10

    Do I have a solution to close a widget from another widget of different classes using events?How could I do that?

    Every fall is to raise higher than Before.

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

      As you need the widget pointer for sending events, you can just call close() method also. And it does the job. So why bother about sending events? Dou you need it asynchronous? Use QmetaObject::invokeMethod(...) with the queued invokation.

      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
        Revu
        wrote on last edited by
        #12

        It should be synchronous with the close of the current widget and raise of other widget.

        Every fall is to raise higher than Before.

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

          Then call

          @
          widget2()->show();
          widget2()->raise();
          widget1()->close();
          @

          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
            Revu
            wrote on last edited by
            #14

            I had already used it in my program and its working.My question is that can't we do the same by passing events between those widgets.in examples given in qt4,in mainwindows there is a sample program named application in which the QCloseEvent has been used but am not able take that and implement to my requirement.It throws a compile error as
            @/usr/include/qt4/QtGui/qwidget.h:84: error: forward declaration of ‘struct QCloseEvent’
            @

            Help me.

            Every fall is to raise higher than Before.

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

              you should add the include for the QCloseEvent, it's only forward declared!

              @
              #include <QtGui/QCloseEvent>
              @

              It's staed in the error message...

              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
                Revu
                wrote on last edited by
                #16

                Thank You.That is clear now.How could I pass the event between two different widgets.Suppose if I had implementted the QCloseEvent in MainWindow then how to call that from my SubWindow?

                Every fall is to raise higher than Before.

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

                  to forward events to a parent, you can just use event->ignore() which should then send the take care that it is also send to the parent (don't know if that also happens to a CloseEvent).

                  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
                    Revu
                    wrote on last edited by
                    #18

                    Well!I have multiple screens.I need to display a particular screen based on the event I pass from my first screen.With signal and slot,I need to write those lines of code in all the files.Suppose if I have some 20 screens then by passing an event from my first screen I should display 10th(or 15th whatever) or close that particular window by having all my control in my first screen.

                    Every fall is to raise higher than Before.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #19

                      Then connect your signals to a slot/some slots in the first screen.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Revu
                        wrote on last edited by
                        #20

                        @Volker:I had done that earlier.How well can I organise these so as to have the control to close my other windows?Just like as we have goto in C.

                        Every fall is to raise higher than Before.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #21

                          It's the same task as if you had events dropping in.

                          EDIT:
                          And as C++ is a superset of C, you have goto - if you really want to use this.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            Revu
                            wrote on last edited by
                            #22

                            Can I traverse from 1st MainWindow to some 15th MainWindow that I have in my application?How well can I do this with signals?

                            Every fall is to raise higher than Before.

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

                              What do you mean with "traverse"? Call each of them in sequence?

                              Of course you can do this. Qt does it all the time. Slots are invoked in the order the connections are created, so that would also "traverse".

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Revu
                                wrote on last edited by
                                #24

                                The GUI should respond depending upon the event received from the C running as back-end.

                                Every fall is to raise higher than Before.

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

                                  OK, here's what I would do, and then I think I'll quit responding to this thread.

                                  I would create a single QObject that is responsible for the communication with the C-based backend. This object receives the call-backs or events or whatever you call them from the backend, and emits corresponding signals for these events. The different windows connect to this object's signals to learn about the data they are interested in.

                                  1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    Revu
                                    wrote on last edited by
                                    #26

                                    @Andre:Thank you for your response.Could you explain the same with a code snippet please.So that I can understand better.

                                    Every fall is to raise higher than Before.

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

                                      [quote author="Revu" date="1301986907"]@Andre:Thank you for your response.Could you explain the same with a code snippet please.So that I can understand better.[/quote]

                                      Not without knowing what your back end looks like and how to communicate with it, no. And to be honest, I don't think I can or want to do that even if you provided the needed code and documentation. I think the concept should be clear though?

                                      1 Reply Last reply
                                      0
                                      • R Offline
                                        R Offline
                                        Revu
                                        wrote on last edited by
                                        #28

                                        I have multiple screens for a outgoing call like Idle,Dial,Progress and Connect screen.My backend controller program is in C.I need to change from Idle to Dial.After I enter the number show progress screen and finally connect screen after the call is established.Based on the events I get from C,my screen will change.Its like with button click I will wait for an event and then display the screen.While showing the other screen,am closing the current(using signal and slot mechanism).So how could I do that with events.

                                        Every fall is to raise higher than Before.

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

                                          Now you are just asking the same question all over again. Sorry, but you really have to do your actual work yourself. Many people have already chimed in to try to help you, but if you just keep repeating your question, we're getting nowhere.

                                          Perhaps a simple state machine is what you want? The different events from your backend could trigger state changes (read the documentation on QStateMachine before asking here how that works!) and your different states could determine what screen is visible.

                                          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