PDA

View Full Version : QT Signals and Slots and Classes



scgrant327
22nd June 2017, 20:03
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

Santosh Reddy
23rd June 2017, 13:46
,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.



// File: ClassA.h
// Don't include ClassA.h / ClassB.h / ClassC.h

// File: ClassA.cpp
#include "ClassA.h"
#include "ClassB.h"
#include "ClassC.h"

// File: ClassB.h
// Don't include ClassA.h / ClassB.h / ClassC.h

// File: ClassB.cpp
#include "ClassA.h"
#include "ClassB.h"
#include "ClassC.h"

// File: ClassC.h
// Don't include ClassA.h / ClassB.h / ClassC.h

// File: ClassC.cpp
#include "ClassA.h"
#include "ClassB.h"
#include "ClassC.h"

ado130
4th July 2017, 06:59
What about design pattern "dependency injection"?