Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [Solved] How to see custom slot in signal slot editor

[Solved] How to see custom slot in signal slot editor

Scheduled Pinned Locked Moved Qt Creator and other tools
17 Posts 2 Posters 44.5k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    I'm using Qt Creator 2.0.1 and I have a custom slot my QMainWindow ... now I have a pushbutton, which on clicked should call the custom slot on the main window. Can do in code yes, but can't do this with the signal-slot editor.

    When I open the signal-slot editor, I see the custom slot on the right but the entire set of slots are disabled. When I select the clicked() signal of the pushbutton, all the slots disappear on the right and I cannot get them back. Basically this is not supported.

    Anyone got this working?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Friedemann.Kleint
      wrote on last edited by
      #2

      The disappearing of the slots on the right is an indication that the signal/slot signatures do not match. Only matching slots are displayed.

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        [quote author="Friedemann.Kleint" date="1283946542"]The disappearing of the slots on the right is an indication that the signal/slot signatures do not match. Only matching slots are displayed.[/quote]

        Nope, I ensured that the signal/slot signatures were matching, still doesn't work.
        Can you give a sample code snip?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Friedemann.Kleint
          wrote on last edited by
          #4

          Not exactly code since we want to do this in Designer, but to make sure we are not talking at cross purposes, what I did is:

          1. Start a QMainWindow form

          2. Context menu 'Change Signals/Slots'

          3. added test(bool)

          4. Drop a QPushButton on the form, switch to Signal/Slot mode

          5. Drew a connection from button to form and connected clicked(bool) with test(bool).

          One thing that might cause problems is the 'canonical' signal/slot signature, that is, Designer permits only 'SLOT ( textChanged ( QString ) )' and not a parameter specified as a const-reference.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            yes your steps got it working, thanks for the same :)
            After doing your steps, then I've to go and add the relevant code in the mainwindow .h and .cpp files ...

            But seems like lot of inconsistencies .. and hard to figure out !

            • No context menu for pushbutton to edit signal/slots
            • Any custom signal/slot added in code is not available to the designer - it appears and disappears as mentioned earlier :)
            • Why not a parameter which is a const?
            • Not documented anywhere is my guess ... pls correct me on that
            1 Reply Last reply
            0
            • F Offline
              F Offline
              Friedemann.Kleint
              wrote on last edited by
              #6

              No context menu for pushbutton to edit signal/slots
              You can specify custom signals and slots only for promoted widgets or main forms. Otherwise, slots and signals are determined by introspection.

              Why not a parameter which is a const?
              Not documented anywhere is my guess … pls correct me on that
              You can use a const-references, freely, but the 'canonical' slot signature will still be " SLOT ( textChanged ( QString ) )". Admittedly, the documentation is not easy to find, for which there is a bug report pending ( "QTBUG-8961":http://bugreports.qt.nokia.com/browse/QTBUG-8961 )

              [ edited to make the bug clickable, tobias ]

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                Friedemann: thanks for the details :)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cabuk
                  wrote on last edited by
                  #8

                  The latest solution!

                  I've started working with Qt 2 days ago and I'm already sniffing the Qt Creator IDE. Actually, there IS a way to create and use custom slots on the "Signals & Slots Editor". The tricky is:

                  • Right click your QMainWindow widget on the design view OR right click the QMainWindow on the Object Inspector;
                  • Choose "Change Signals/Slots..." on the menu.

                  Shall I explain the given screen or you guys can figure it out? ;)

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    thanks Cabuk ... should've seen this :)

                    one more question, once this custom slot is added in the designer, how and where do I code for it?
                    It gets added in Ui_MainWindow.h, editing that directly is not recommended.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Cabuk
                      wrote on last edited by
                      #10

                      I disagree.

                      Why you think that it's not "recommended"? My concept is that the Qt Creator - and any other IDE - is here to help us code, making it easy, simple, and fast to do. The Qt Creator is no exception.

                      About the method I explained, it's meant to be hand coded by declaring the existence of custom signals/slots to the IDE.

                      Alternatively you can use the "automatic" slot generation, which creates "ugly method names" - in my opinion -, but works too:

                      • Right click any widget or any action on the Action Editor
                      • choose the option Go to slot...
                      • Choose your signal and click OK.

                      This way the Qt Creator will generate the slot definition and declaration (.h and .cpp files), and will show you the newly created slot on the cpp.

                      PS.: You can create these "automatic" slots by hand, since the Qt compiler will detect it, but this isn't recommended, for real :P

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #11

                        @cubuk, in my opinion, I meant, hand tweaking the generated ui header file is not recommended, as next time you make UI changes in designer, it will get overridden ...

                        ... ok using designer this is what I want to do.

                        In my mainwindow, I want a custom slot "void mySlot()" and I want to add code into it. I want to click a button and invoke mySlot on mainwindow.

                        Now can you help in step by step instructions, how to go about it using designer to create the custom slot...

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Cabuk
                          wrote on last edited by
                          #12

                          No, you won't hand code the ui file. Do not confuse the C++ class files (.h and .cpp) and the user interface file (.ui). This second one is modified on the designer view, where my tip comes. The class files are the code you'll write. If you indicate on the designer your custom signals/slots - using my method -, it won't reflect on the class files. It just says that your class have - or will have - the given signal/slot.

                          By example:

                          • Add the slot on the designer view to your QMainWindow
                          • Create the definition of your slot on the .h file:
                            @public slots:
                            void mySlot();@
                          • Create the declaration of your slot on the .cpp file:
                            @void MainWindow::mySlot()
                            {
                            // Add your code here
                            }@
                          • Run it ;)

                          This is the expected behavior since the .h and .cpp files are meant to be hand coded by you. Did I answer your question? :D

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #13

                            so you create the custom slot in designer and then write code for it in mainwindow.h and mainwindow.cpp. yes that works.

                            now, suppose I already have a custom slot(s) coded in my mainwindow.h, why doesn't it show up in the signal/slot editor for me to connect them? that was my original question. Suppose I already have coded many slots, connecting them via signal slot editor would be a good feature I think. Or is there a way to get these too and I missed it yet again :P

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              Cabuk
                              wrote on last edited by
                              #14

                              bq. If you indicate on the designer your custom signals/slots – using my method -, it won’t reflect on the class files.

                              That's the point you missed... By using the method I said, it won't touch your class files, so you can declare here all your already-made slots with ease, and use it on the Signal & Slots Editor :D

                              1 Reply Last reply
                              0
                              • ? This user is from outside of this forum
                                ? This user is from outside of this forum
                                Guest
                                wrote on last edited by
                                #15

                                ok ok i get it and thanks for the replies :)

                                1 Reply Last reply
                                0
                                • C Offline
                                  C Offline
                                  Cabuk
                                  wrote on last edited by
                                  #16

                                  You're welcome! And sorry if I misunderstood your question, but I just wanted to be the most verbose possible to explain it :o

                                  1 Reply Last reply
                                  0
                                  • ? This user is from outside of this forum
                                    ? This user is from outside of this forum
                                    Guest
                                    wrote on last edited by
                                    #17

                                    i learnt a new trick with the creator :)

                                    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