Another and easy approach would be if the class NetworkListWorker receive again a const DirItemInfo *parent, but sets m_parent as its own instance using the operator '=', in this case it never gets deleted outside the worker thread.
Suppose the code changed:
NetworkListWorker::NetworkListWorker(LocationItemDirIterator * dirIterator, DirItemInfo * mainItemInfo, const DirItemInfo *parent) :
DirListWorker(dirIterator->path(), dirIterator->filters(), dirIterator->flags() == QDirIterator::Subdirectories ? true : false),
m_dirIterator(dirIterator),
m_mainItemInfo(mainItemInfo),
m_parent(0)
{
if (parent != 0)
{
m_parent = new UrlItemInfo(); // UrlItemInfo is for remote
*m_parent = *parent; // not sure it works, needs be reviewed
}
mLoaderType = NetworkLoader;
// this would not be necessary and can be removed
parent->connectDestructionSignal(this, SLOT(onParentDestroyed()));
}
Another and easy approach would be if the class NetworkListWorker receive again a const DirItemInfo *parent, but sets m_parent as its own instance using the operator '=', in this case it never gets deleted outside the worker thread.
Suppose the code changed:
NetworkListWork er::NetworkList Worker( LocationItemDir Iterator * dirIterator,
DirItemInfo * mainItemInfo,
const DirItemInfo *parent) : er(dirIterator- >path() ,
dirIterator ->filters( ),
dirIterator ->flags( ) == QDirIterator: :Subdirectories ? true : false), or(dirIterator) , nfo(mainItemInf o),
DirListWork
m_dirIterat
m_mainItemI
m_parent(0)
{
if (parent != 0)
{
m_parent = new UrlItemInfo(); // UrlItemInfo is for remote
*m_parent = *parent; // not sure it works, needs be reviewed
}
mLoaderType = NetworkLoader;
// this would not be necessary and can be removed >connectDestruc tionSignal( this, SLOT(onParentDe stroyed( )));
parent-
}
NetworkListWork er::~NetworkLis tWorker( )
{
delete m_dirIterator;
delete m_mainItemInfo;
if (m_parent != 0)
{
delete m_parent;
}
}