If you have problem like this it usually points to a design problem. You should be able to refactor your code to remove circular references (I virtually guarantee that it's possible).
If you have problem like this it usually points to a design problem. You should be able to refactor your code to remove circular references (I virtually guarantee that it's possible).
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
I sort of agree with this, but sometimes is really is necessary for two classes to know something about each other. But typically, the two classes don't actually need pointers to each other, what they need is to pass information between themselves. In Qt, this is usually done with signals and slots. Each class has a signal "sendSomeInformation( const SomeInfo & )" and a slot "receiveSomeInformation( const SomeInfo & )" which are cross-connected (in a way that doesn't cause infinite recursion). When Class1 changes the information, it emits the signal, which Class2 receives and can update its internal state accordingly. Likewise, the same thing happens when Class2 changes the state of the information. If there is more information that needs to be shared, either make a bigger (less granular) shared object or implement multiple signal / slot pairs.If you have problem like this it usually points to a design problem.
Note that in this case, neither Class1 or Class2 know anything about the other, and don't need to; all they both know about is the "SomeInfo" class they pass back and forth. Likewise, the class that constructs the instances of Class1 and Class2 only needs to know that each of them has certain signals and slots that need to be connected, but that class doesn't need to know anything more about "SomeInfo" except that a reference will be passed in the connection.
The nice part about this from a design point of view is that you could completely replace Class1 or Class2 with a totally new implementation, and the opposite partner wouldn't know or care, so long as the signal, slot, and "SomeInfo" remained the same. The only class that would care is the one that constructs the two class instances.
Bookmarks