How to send information between two classes where one class is instantiated inside the other?
You have to provide a method to access that class.
Example:
// basket.h
#include "apple.h"
class Basket
{
...
int number_of_apples;
Apple instantiatedApple;
public: // accessor
int numberOfApples() const
{ return number_of_apples; }
}
// basket.h
#include "apple.h"
class Basket
{
...
int number_of_apples;
Apple instantiatedApple;
public: // accessor
int numberOfApples() const
{ return number_of_apples; }
}
To copy to clipboard, switch view to plain text mode
And below is a simple mechanism on how to access it.
// apple.h
class Basket;
class Apple
{
Basket* basket;
void methodinsideapple();
public:
inline void setBasket(Basket* basket)
{ this->basket = basket; }
}
// apple.cpp
#include "apple.h"
#include "basket.h"
Apple::methodinsideapple()
{
int numOfApples = basket->numberOfApples(); // you got it
...
}
// apple.h
class Basket;
class Apple
{
Basket* basket;
void methodinsideapple();
public:
inline void setBasket(Basket* basket)
{ this->basket = basket; }
}
// apple.cpp
#include "apple.h"
#include "basket.h"
Apple::methodinsideapple()
{
int numOfApples = basket->numberOfApples(); // you got it
...
}
To copy to clipboard, switch view to plain text mode
How can I pass the dynamic info based on user interaction back and forth between mainwindow class and QWizard class.
You can use similar technique to solve your real problem. Maybe design pattern will be a great solution for complex class interaction.
Bookmarks