Solved How to connect two separate classes using signal/slots.
-
It's a method call, you should've seen it while learning C++.
-
@kshegunov I still am. I'm a second year CS/CE student.
-
@rocklionmba
Hi
Its just non pointer syntax for calling a method/access member.C privateMemberVAR;
privateMemberVAR.methodToBeCalledFromA();in contrast to
C *privateMemberVAR = new C;
privateMemberVAR->methodToBeCalledFromA(); -
@mrjj so it would be """ interior_paint:: privatememberVAR.somefunction(){ //code here }""" ?
-
Hi
Where ?
In the slot ?The main trick here is that, the slot calls the private member. Not directly from outside.
Its triggered via the signal.Maybe show how interior_paint looks like.
and it will end up in something like
void interior_paint::TheNewSlot() {
privatememberVAR.somefunction();
} -
@mrjj so in terms that I'm using, class A would be MainWindow, B is the extra class to handle info, and C is interior_paint?
-
@rocklionmba
Well B is the interior_paint that has the private member you want to call a method on
and A is mainwin.
C is the private member class (inside interior_paint )The mainwindow will fire its new signal signalFromAtoC and that will call
delegateToCSlot that call its private class and its function. -
you can do it by sending signals from both the classes and catch in a slot
-
@mrjj Hey, so I finally had the chance to try it out today and I noticed a problem with it. I'm using a dynamic array, so it naturally has to be a pointer for it to work. Also, a and b in the example are together, while in the actual code both are made in their constructors. Would the pointer make a problem? and would I have to move the location of where the variables are made for it to work?
-
@rocklionmba said in How to connect two separate classes using signal/slots.:
Would the pointer make a problem?
Not at all. Just make sure they are initialized before any of the slots can be triggered.