Results 1 to 5 of 5

Thread: QT Creator won't recognize a slot

  1. #1
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QT Creator won't recognize a slot

    Hello,

    I wish to connect a clicked() signal (from a button) to a slot that I have in my MainWindow class.

    In mainwindow.h I have:
    protected slots:
    void viewDataset();

    but when I try to connect the slot in the ui I do:

    sender / signal / reciever / slot
    button / clicked() / MainWindow /

    and for whatever reason viewDataset() is not an option in the slot selection box.

    Is there anything I need to do in order to get the creator/designer to recognize my new slot ?

    thanks,
    lucas

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Creator won't recognize a slot

    Yes, you need to add your slot to designer, it doesn't pick up anything from your source code, so click the "Add" button.

  3. #3
    Join Date
    Feb 2010
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT Creator won't recognize a slot

    Ignore: I think what he means is, he has a custom slot in his class, but that custom slot is not showing up in the "<slots>" drop-down when he clicks "Add". I agree, and can confirm that my custom slots (public or protected) do not show up in that drop-down. The only slots listed are those inherited from QMainWindow and QObject. I've tested this in both Windows and Linux. Maybe I'm using it wrong? It's just really frustrating because when you perform a clean, it also wipes out any connect() statements you added manually in ui_whatever.h.

    EDIT:

    To add a custom slot for a button:
    1. Switch to signal/slot edit mode (F4).
    2. Click and drag on the button to initiate the signal/slot editor.
    3. In the left pane, select your "clicked()"/"triggered()"/whatever signal.
    4. Below the right pane, click the "edit" button.
    5. Below the top pane, click the "Add" button, and enter the call for your custom slot.
    6. Click OK, and your custom slot should now be in the right pane.
    7. Select your custom slot, click OK, and build your project.

    After you do this, the slot will show up in the <slots> drop-down, but since a signal/slot connection is created for you at this point, you'll only need to utilize it from the drop-down if you use it with another signal.

    Ignore: Unfortunately, this doesn't work for menus, since the signals/slots edit mode wants to attach to the menu bar, rather than the menu items. If anyone has a workaround for this, I'd greatly appreciate it...

    EDIT:

    There is an easy trick to getting Creator to automatically connect signals to your custom slots, regardless of what they are: You have to name the slot function appropriately.

    You have to name them using the format "on_<sender object name>_<signal>". For example, if you have a button named "calculateButton", and you want to launch your calculate function via the "clicked()" signal, you must name your function: "on_calculateButton_clicked".
    Qt Code:
    1. void on_calculateButton_clicked();
    To copy to clipboard, switch view to plain text mode 
    Note that if you're hand-coding everything, this doesn't matter, you can name your slots and functions whatever you want. But to make it easier when working in Creator, using this naming convention for slots makes it less of a headache.
    Last edited by TheJim01; 23rd February 2010 at 17:07.

  4. The following 3 users say thank you to TheJim01 for this useful post:

    Computer Hater (11th November 2010), JovianGhost (14th March 2010), mwgobetti (14th November 2011)

  5. #4
    Join Date
    Sep 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: QT Creator won't recognize a slot

    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?

  6. #5
    Join Date
    Dec 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Creator won't recognize a slot

    Quote Originally Posted by cabuk View Post
    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?
    Hey, it's 3 years later, but I want to thank you for this!!!

Similar Threads

  1. process QTextDocument and recognize newlines?
    By -=Freaky=- in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2009, 15:57
  2. Replies: 2
    Last Post: 12th February 2009, 09:53
  3. How do I get Qt to recognize the oci driver.
    By yleesun in forum Qt Programming
    Replies: 11
    Last Post: 19th January 2009, 03:50
  4. How to recognize a letter from a Qstring?
    By luffy27 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2007, 19:22
  5. Getting Qt to recognize plugins...
    By KShots in forum Qt Programming
    Replies: 4
    Last Post: 21st April 2007, 10:05

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.