Results 1 to 6 of 6

Thread: Indicating/catching signals

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Indicating/catching signals

    Hello!

    I've got in my header file signal:

    Qt Code:
    1. signals:
    2. void mySignal(int i);
    To copy to clipboard, switch view to plain text mode 

    Sometimes mySignal(int i) is emitted by different slots:

    Qt Code:
    1. connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunc));
    2.  
    3. [...]
    4.  
    5. void MainWindow::myFunc()
    6. {
    7. mySignal(10);
    8. }
    To copy to clipboard, switch view to plain text mode 

    How can I catch that signal?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Indicating/catching signals

    That should be
    Qt Code:
    1. emit mysignal(10);
    To copy to clipboard, switch view to plain text mode 

    And:
    http://doc.qt.nokia.com/4.7/qsignalspy.html

  3. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Indicating/catching signals

    Would it be wrong if I do it that way:

    Qt Code:
    1. connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunc()));
    2. connect(this, SIGNAL(mySignal(int), this, SLOT(myOtherFunc(int)));
    3.  
    4. [...]
    5.  
    6. void MainWindow::myFunc()
    7. {
    8. mySignal(10);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I've tried this, and it works, but I don't know if it's correct use of signals.

    thanks in advance
    best regards
    Tomasz

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Indicating/catching signals

    Sure, there's no problem with that.

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

    Default Re: Indicating/catching signals

    Quote Originally Posted by tbscope View Post
    That should be
    Qt Code:
    1. emit mysignal(10);
    To copy to clipboard, switch view to plain text mode 
    But 'emit' is only syntactic suger. You can omit and save the keystrokes at the expense of code readability.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Indicating/catching signals

    Quote Originally Posted by squidge View Post
    But 'emit' is only syntactic suger. You can omit and save the keystrokes at the expense of code readability.
    I honnestly didn't know that.

Similar Threads

  1. Replies: 1
    Last Post: 19th January 2010, 22:35
  2. emitting and catching signals
    By srohit24 in forum Qt Programming
    Replies: 12
    Last Post: 4th August 2009, 19:32
  3. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 23:18
  4. Catching X Events
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2006, 13:43

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.