PDA

View Full Version : Multiple calls which create multiple instances of QSignalMapper



naughtykid
19th October 2011, 02:22
The Open() function will be initiate a number of times based on user's preference.
I learned that QSignalMapper will be clear by it's parent upon the destruction of application.
But what would happened in this case?

Below are the code snippet:



void class1::Open()
{
// opened a folder & and extract a list of directories ...

QSignalMapper *signalMapper = new QSignalMapper(this);
for(int i = 0; i < directoryList.size(); i++)
{
std::cout << directoryList[i].toStdString() << std::endl;

DirWidget *dirWidgetPtr = new DirWidget(directoryList[i]);
signalMapper->setMapping(dirWidgetPtr->_buttonPtr, directoryList[i]);
connect(dirWidgetPtr->_buttonPtr, SIGNAL(clicked()), signalMapper, SLOT(map()));
_flowLayoutPtr->addWidget(dirWidgetPtr);

}
connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(GetDir(QString)));
}

ChrisW67
19th October 2011, 06:14
But what would happened in this case?
What would happen to what? The QSignalMapper(s) you create will be destroyed when their parent instance of class1 is destroyed. The DirWidgets will be destroyed when their _flowLayout is destroyed (assuming it is a well behaved QLayout derivative).

naughtykid
19th October 2011, 09:30
Thanks for the reply ChrisW67.

To be specific:
So is that means class1 keeps all the created QSignalMapper instances until it destroyed?
Or it destroy the previous one right after I initiate a new QSignalMapper?