Results 1 to 3 of 3

Thread: Why do i need to declare a function as a slot?

  1. #1
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Why do i need to declare a function as a slot?

    Hello all,

    I am new to c++, Linux and and qt!

    What I don't understand is why I need to declare a function as a public slot in order to connect it with a signal.

    Is it possible to connect a public function (not declared as a slot) with a signal?.

    Does that means that if I want to connect a function with a signal I have to declare it as a slot before?

    How can i connect more than one function with a signal. (for example if condition a exist execute the first function otherwise execute the second)?

    Finally: All the tutorials i have been through were using the code generation technique for the GUI. If i use the designer i only need to bother about the connection right?

    Many thanks in advance,

    Christos

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why do i need to declare a function as a slot?

    Quote Originally Posted by cbarmpar View Post
    What I don't understand is why I need to declare a function as a public slot in order to connect it with a signal.
    You have to do that, so that moc will know for which methods it should generate meta-data. Take a look at the files generated by moc.

    Quote Originally Posted by cbarmpar View Post
    Is it possible to connect a public function (not declared as a slot) with a signal?.
    No.

    Quote Originally Posted by cbarmpar View Post
    Does that means that if I want to connect a function with a signal I have to declare it as a slot before?
    Yes.

    Quote Originally Posted by cbarmpar View Post
    How can i connect more than one function with a signal. (for example if condition a exist execute the first function otherwise execute the second)?
    If you want to route signals depending on the values of their parameters, you have to do so in your code.

    Quote Originally Posted by cbarmpar View Post
    All the tutorials i have been through were using the code generation technique for the GUI. If i use the designer i only need to bother about the connection right?
    No, you need a widget subclass which will use the code generated from the .ui file.

    See http://doc.trolltech.com/4.4/designe...component.html

  3. The following user says thank you to jacek for this useful post:

    cbarmpar (3rd September 2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why do i need to declare a function as a slot?

    Many thanks friend that was a clear answer.

    Regards

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.