我正在使用QSharedPointer作为包含插槽功能的对象。我的期望是,即使包含这个指针的对象被破坏但它仍然存在并处理QProcess::finished
信号,但事实并非如此。
我创建了一个QProcess
并将其连接到插槽。 Pdf对象很快就会被破坏,所以我使用QSharedPointer使m_symLinks
对象保持活着并处理finished
信号,但在处理之前它也会死掉。
void PDf::createPDF()
{
// ....
QProcess *myProcess= new QProcess();
connect(myProcess, SIGNAL(finished(int)), m_symlinks.data(), SLOT(createPdfLink(int)) );
myProcess->start("sh",args); // yes args is valid variable defined (now shown)
// note if I waitForFinished() here than my slot does get called but the slot object seems to die if I don't wait here.
}
头文件是:
class Pdf: public QObject
{
Q_OBJECT
Pdf() : QObject(parent)
{
m_symlinks = (QSharedPointer <Symlinks>) (new Symlinks);
}
QSharedPointer <Symlinks> m_symlinks;
}