Results 1 to 10 of 10

Thread: creating custom signal

  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default creating custom signal

    can we create custom signal in qt? if yes how can it be done?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: creating custom signal

    yes, you can
    Qt Code:
    1. class MyObject: public QObject
    2. {
    3. Q_OBJECT
    4. ....
    5. signals:
    6. void mySignal(int myParameter);
    7. ....
    8. private:
    9. void emitMySignal();
    10. ....
    11. };
    12.  
    13. ...
    14. void MyObject::emitMySignal()
    15. {
    16. emit mySignal(10);
    17. }
    18. ...
    To copy to clipboard, switch view to plain text mode 

    i.e. you need to inherits from QObject, add Q_OBJECT macro, define your signal in signals section, emit signal in some method using emit.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Cupidvogel (20th April 2015)

  4. #3
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: creating custom signal

    thanks spirit.

    mean this is how the signal should be connected

    connect(this,SIGNAL(mySignal),this,SLOT(func1)); or

    connect(class name ,SIGNAL(mySignal),this,SLOT(func1));

  5. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: creating custom signal

    Quote Originally Posted by aj2903 View Post
    thanks spirit.

    mean this is how the signal should be connected

    connect(this,SIGNAL(mySignal),this,SLOT(func1)); or

    connect(class name ,SIGNAL(mySignal),this,SLOT(func1));
    it should look like:
    Qt Code:
    1. connect(pointerToSomeObject, SIGNAL(someSignal(parameterType)), pointerToSomeObject, SLOT(someSlot(parameterType)));
    To copy to clipboard, switch view to plain text mode 

    so your first version is almost correct - you forgot about patameter type, for example: mySignal(int) instead of mySignal
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #5
    Join Date
    Nov 2012
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: creating custom signal

    Here I found a nice explaination may be this helps to you
    http://qtitkvtkhelp.blogspot.in/2013...l?view=sidebar

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,552
    Thanks
    13
    Thanked 1,579 Times in 1,508 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: creating custom signal

    4-year old thread... new record?

  8. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: creating custom signal

    Should change the username to qt.itk.vtk.hopeless. For the life of me, I can't understand why people respond to ancient posts. Do they not read the date before replying?

    Then again, given the user name and the name of the site in the link, this looks like self-serving spam to me.

  9. #8
    Join Date
    Oct 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: creating custom signal

    who is more helpless, the one replying to a 4-year-old post, or the one replying to the reply? (or in my case, the one replying to the one replying to the one who replied 4 years late )

    That link was self-serving alright, it probably is one of those traffic booster bots that go around posting replies like that just to boost traffic at the home site, even though the replies may seem legit, its just a way to boost traffic so they can get more exposure to their google text ads, and in turn make money, it ALWAYS comes down to money (always). And why? because the more money you have the better chance you have of getting girlfriend... so really it all comes down to that "other" thing (unless you are a girl, then it all just comes down to shoes).

  10. #9
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: creating custom signal

    eight of helpless people

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: creating custom signal

    I guess we're just not going to let this thread die, are we?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. how to add custom signal to designer
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2009, 10:26
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  4. Custom signal in qt designer
    By txandi in forum Qt Tools
    Replies: 1
    Last Post: 4th December 2008, 20:25
  5. Creating custom slots
    By harb37 in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2008, 18:10

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.