0

我将 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;

}
4

0 回答 0