Thanks for the reply.
The shared object (TargetTracking) is instantiated in the gui thread and passed as a constructor argument for the reading and writing threads
m_targetTracking = new TargetTracking( ...);
m_targetTrackingThread = new TargetTrackingThread( m_targetTracking); // writing thread
m_targetTrackingThread->start();
m_targetTracking = new TargetTracking( ...);
m_targetTrackingThread = new TargetTrackingThread( m_targetTracking); // writing thread
m_targetTrackingThread->start();
To copy to clipboard, switch view to plain text mode
The TargetTrakingThread is declared as
class TargetTrakingThread
: public QThread { Q_OBJECT
public:
TargetTrakingThread( TargetTracking* targetTracking);
~TargetTrakingThread();
void autoTargetAlign();
void stopTargetAlign() { m_stop = true; }
protected:
void run();
private:
TargetTracking* targetTracking;
bool m_stop;
};
class TargetTrakingThread : public QThread {
Q_OBJECT
public:
TargetTrakingThread( TargetTracking* targetTracking);
~TargetTrakingThread();
void autoTargetAlign();
void stopTargetAlign() { m_stop = true; }
protected:
void run();
private:
TargetTracking* targetTracking;
bool m_stop;
};
To copy to clipboard, switch view to plain text mode
The waitForAlign method is essentially polling the data member and is defined as
void TargetTracking::waitForAlign()
{
while (!m_targetIsAligned && m_autoTargetAlign) {
usleep( 100000);
}
}
void TargetTracking::waitForAlign()
{
while (!m_targetIsAligned && m_autoTargetAlign) {
usleep( 100000);
}
}
To copy to clipboard, switch view to plain text mode
This method is called by the readingThread
The data member m_targetIsAligned is set in a different method TargetTracking::alignTarget as shown
void TargetTracking::alignTarget()
{
...
locateTarget();
// check if the target is centred
if (!m_overrideTargetlAlignment) {
m_targetIsAligned = checkIfTargetCentred();
} else {
m_targetIsAligned = true;
}
...
}
void TargetTracking::alignTarget()
{
...
locateTarget();
// check if the target is centred
if (!m_overrideTargetlAlignment) {
m_targetIsAligned = checkIfTargetCentred();
} else {
m_targetIsAligned = true;
}
...
}
To copy to clipboard, switch view to plain text mode
This method is called by the writing thread
I reviewed the code, and the only instance where const appears is in the different get methods for the TargetTracking data members. There are two methods setting the control booleans and are defined as
class TargetTracking
: public QObject{
...
void setAutoTargetAlign( const bool align) { m_autoTargetAlign = align; }
void overrideTargetAlignment( const bool action) { m_overrideTargetAlignment = action; }
...
}
class TargetTracking : public QObject
{
...
void setAutoTargetAlign( const bool align) { m_autoTargetAlign = align; }
void overrideTargetAlignment( const bool action) { m_overrideTargetAlignment = action; }
...
}
To copy to clipboard, switch view to plain text mode
Could these instance of const be the root of my problem?
Also, there is no inheritance for the classes mentioned here. Note that TargetTracking has some static methods declared
So the addition of the mutable attribute still puzzle me.
Daniel
Bookmarks