Results 1 to 5 of 5

Thread: Signals and slots

  1. #1
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Signals and slots

    I just don't seem to get this signal and slot thing, I'm trying to have a funtion executed when Qpushbutton is pressed but I can't get it to work correctly :

    i have a public slot
    void selectb1();
    and a signal
    goselect();

    now I've connected those 2
    connect(this,SIGNAL(goselect()),SLOT(select()));

    and then I do
    connect(&button1,SIGNAL(clicked()),SLOT(select());

    but when I click on the button select ain't called

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signals and slots

    Do you have the Q_OBJECT macro in your class declaration?

    BTW:
    Qt Code:
    1. connect(&button1,SIGNAL(clicked()),SLOT(select());
    To copy to clipboard, switch view to plain text mode 
    Since button1 is allocated on the stack, it will get destroyed when that function exits. You should create it on the heap.
    Your code works only if button1 is a member of that class.

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signals and slots

    Where and how did you declare the signal "goselect()"? And where do you emit it?

  4. #4
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Signals and slots

    It's emited at the end of select and defined in the class defention in the header file

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signals and slots

    If it's emitted within select, then unless you call select manually, it won't be emitted. And it all seems weird as you'd create an infinite loop. Can we see the exact code? Both declarations and definitions of the class and especially the places where the concerned signal and slot are used.

Similar Threads

  1. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 00:24
  2. Nested signals and slots
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 09:47
  3. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12
  4. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 22:09
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

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.