Results 1 to 8 of 8

Thread: Signal in base class Slot in Subclass

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Signal in base class Slot in Subclass

    hi,
    I have a code that works with a custom signal genreated by a class and then its handled by the same class only.

    now i tried doing the same by genreating signal from the base class and then handle it with a slot at subclass but that is not working.

    i have attached both the copies of the code..
    please tell me what change i should do.

    thanks in advance
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal in base class Slot in Subclass

    First of all, subclass.h is missing define guards and the class declaration is missing a semi-colon (. Furthermore, you do:
    Qt Code:
    1. connect( pushButton_clear, SIGNAL( customSignal (const QString&) ), this, SLOT( mySlot(const QString&) ) );
    To copy to clipboard, switch view to plain text mode 
    Which doesn't compile either because pushButton_clear is a private member of the base class, thus inaccessible from the subclass. However, customSignal() is not a signal of the button anyway so you should change it to "this". Last but not least, you never create an instance of the subclass.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: Signal in base class Slot in Subclass

    OKie that was because the code was written in some other pc and i was not able to send the exact code which i tried.
    ---------------------------------------------------------------------------------!

    now with those error being corrected!

    Please tell me how to handle a signal emitted by a slot of one class, by a slot of some other class?

    should i need to inherit the class that emits the signal or create an object of the class that emits the signal?

    consider the following situation where i have a class that reads the socket for data.
    whenever there is a data arrived at the port readyread() signal will be emitted and i connect this signal to the slot of the same class. This slots reads the header of the data. based on the header i l emit a signal.
    This signal will be captured by any class that has a slot connected to this particular signal.
    In this case who will be the sender of the signal to be filled in the connect call.

    in genral if there is a base class slot that emits a signal how will i handle the signal thru the connect statement in the derived class?

    Qt Code:
    1. connect(?,SIGNAL(baseclass signal1()),this,SLOT(onbaseclasssignal1())
    To copy to clipboard, switch view to plain text mode 

    I am a newbie to QT.

    can anyone please enlighten me on this.....!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal in base class Slot in Subclass

    The sender is "this".
    J-P Nurmi

  5. #5
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Signal in base class Slot in Subclass

    i tried this but its not working

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal in base class Slot in Subclass

    QObject::connect() outputs a warning to the debug output upon failed connections.
    J-P Nurmi

  7. #7
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Signal in base class Slot in Subclass

    no there is no such message coming at the terminal window...!
    should i need to enable anything to get such messages ....!
    can u pls b more brief with ur replies, so that i would be greatly benifited with it...

    the pro file is in debug mode only.

    thanks for ur patience...

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal in base class Slot in Subclass

    Could you start with reading through this, please: Signals and Slots?
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    csvivek (8th May 2008)

Similar Threads

  1. Replies: 4
    Last Post: 19th March 2008, 17:47
  2. send own class reference throught signal
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2008, 21:55
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  4. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 22:37
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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.