Results 1 to 3 of 3

Thread: Define and emit signals

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Define and emit signals

    Hi all!

    I saw how to define and emit signals but it is not quite working. I need to know if there is a problem to connect a slot to a signal from another class and emited by that other class.

    So, I have a base class where my gui is handled and a client class where I do some tcp things.

    on the client.h I simple define the signal like this:

    signals:
    void data_READY();

    then on the base class I do:

    Client *client = new Client();
    connect(not_sure_what_to_set_here, SIGNAL(client->data_READY()),this,SLOT(login_data()));

    1-Is it allowed to connect slots to signals from other classes?

    if yes

    2-What would be the first parameter on the connect?

  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: Define and emit signals

    Yes, it is allowed to connect slots and signals across class objects.

    The first parameter is the sender of the signal, in your case that would be the object "client".
    Example:

    Qt Code:
    1. connect(client, SIGNAL(data_READY()), this, SLOT(login_data()));
    To copy to clipboard, switch view to plain text mode 

    Note also that SIGNAL is a macro to instruct the moc. The SIGNAL macro only takes the name of a function, not a pointer to a function.

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

    ruben.rodrigues (24th June 2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Define and emit signals

    Quote Originally Posted by tbscope View Post
    Yes, it is allowed to connect slots and signals across class objects.

    The first parameter is the sender of the signal, in your case that would be the object "client".
    Example:

    Qt Code:
    1. connect(client, SIGNAL(data_READY()), this, SLOT(login_data()));
    To copy to clipboard, switch view to plain text mode 

    Note also that SIGNAL is a macro to instruct the moc. The SIGNAL macro only takes the name of a function, not a pointer to a function.
    Thank you! I just had time to test it now and it works fine. This also solve my other thread about using the QThread..

Similar Threads

  1. Thread shall emit signals with "complex" argument
    By Boron in forum Qt Programming
    Replies: 8
    Last Post: 17th June 2010, 18:22
  2. "emit" keyword optional when calling signals?
    By will49 in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2008, 01:13
  3. emit Signals
    By Fastman in forum Qt Programming
    Replies: 5
    Last Post: 22nd August 2007, 13:14
  4. QHttp and readyRead signals emit sequence
    By balitong in forum Qt Programming
    Replies: 4
    Last Post: 19th June 2006, 05:22
  5. Replies: 2
    Last Post: 6th January 2006, 21:15

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
  •  
Qt is a trademark of The Qt Company.