Results 1 to 3 of 3

Thread: QT Signals and Slots and Classes

  1. #1
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question QT Signals and Slots and Classes

    I have three classes.

    Class A: websocket connection to my server.

    Class B: QTimer that generates Demo data to hand off to Class A for posting on to my server and CLASS C for updating the QML UI.

    Class C: generic functions used throughout the application. has Q_PROPERTY entries for updating the QML UI. data warehouse for all Demo data generated by Class B.

    Now, say I want to emit a signal in Class B that is connected to a slot in Class A that initiates the connection to my server. No issue. However, once the connection is made, I want Class A to emit signal that is connected to a slot in Class B that starts the QTimer for Demo data creation. Of course, once the Demo data is created, Class B then emits a signal connected to Class C that updates a graph on the UI.

    My issue is how do I set up the CPP & H files so that Class A can see all the slots in Class C, and Class C can see all the slots in Class A? Basically, how can each class see the slots of ALL other classes so they can be used?
    --Sam

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QT Signals and Slots and Classes

    ,how can each class see the slots of ALL other classes so they can be used?
    It is basic C/C++ include dependency problem.

    Do this way.

    Qt Code:
    1. // File: ClassA.h
    2. // Don't include ClassA.h / ClassB.h / ClassC.h
    3.  
    4. // File: ClassA.cpp
    5. #include "ClassA.h"
    6. #include "ClassB.h"
    7. #include "ClassC.h"
    8.  
    9. // File: ClassB.h
    10. // Don't include ClassA.h / ClassB.h / ClassC.h
    11.  
    12. // File: ClassB.cpp
    13. #include "ClassA.h"
    14. #include "ClassB.h"
    15. #include "ClassC.h"
    16.  
    17. // File: ClassC.h
    18. // Don't include ClassA.h / ClassB.h / ClassC.h
    19.  
    20. // File: ClassC.cpp
    21. #include "ClassA.h"
    22. #include "ClassB.h"
    23. #include "ClassC.h"
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    scgrant327 (10th July 2017)

  4. #3
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QT Signals and Slots and Classes

    What about design pattern "dependency injection"?

Similar Threads

  1. Replies: 10
    Last Post: 18th September 2014, 14:58
  2. Replies: 2
    Last Post: 18th April 2013, 12:15
  3. Replies: 2
    Last Post: 29th June 2012, 09:32
  4. Signals/slots between classes
    By been_1990 in forum Qt Programming
    Replies: 19
    Last Post: 27th November 2009, 13:04
  5. Signals and Slots between 2 classes
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2006, 00:34

Tags for this Thread

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.