Pointer to a QProcess object in class constructor qt GUI failure

I have a GUI GUI application that contains a DS9 widget derived from QFrame to open and work with an external program. The implementation of the class is as follows:

ds9.h

#ifndef DS9_H
#define DS9_H

#include <QFrame>
#include <QProcess>

class DS9 : public QFrame
{
    Q_OBJECT

public:
    explicit DS9(QWidget *parent = 0);
    ~DS9();  

signals:


public slots:
    void runDS9();

private:
    QProcess *ds9;
};

#endif // DS9_H

ds9.cpp

DS9::DS9(QWidget *parent):
    QFrame(parent)
{
    ds9 = new QProcess();
    ds9->setProgram("ds9");
    QStringList arguments;
    arguments << "-invert" << "-zscale";
    ds9->setArguments(arguments);
}

DS9::~DS9()
{
    delete ds9;
}

void DS9::runDS9()
{
    ds9->start();
}

However, when the program starts, instead of displaying the graphical interface, a black (not empty) window appears and immediately crashes. The error message is as follows:

*** Error in `./lightcurve_examiner': double free or corruption (out):        0x00000000013f0610 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x77a8d)[0x7f0a9dcada8d]
/lib64/libc.so.6(cfree+0x5cd)[0x7f0a9dcb9d2d]
/lib64  /libQt5Core.so.5(_ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11Q    ThreadData+0x2d0)[0x7f0a9efd0a20]
/lib64/libQt5Core.so.5(+0x2d9983)[0x7f0a9f024983]
/lib64/libglib-2.0.so.0(g_main_context_dispatch+0x15a)[0x7f0a9d2eca8a]
/lib64/libglib-2.0.so.0(+0x49e20)[0x7f0a9d2ece20]
/lib64/libglib-2.0.so.0(g_main_context_iteration+0x2c)[0x7f0a9d2ececc]
.....

However, if I do not set QProcess *ds9as a member of the class, i.e. doing something like this:

in .h:

...
    private:
      //  QProcess *ds9;
...

in .cpp:

void DS9::runDS9()
{
    QProcess * ds9 = new QProcess();
    ds9->setProgram("ds9");
    QStringList arguments;
    arguments << "-invert" << "-zscale";
    ds9->setArguments(arguments);
    ds9->start();
}

everything works fine, i.e. the graphical interface starts up normally, and by calling the slot, the program is correctly called.

: QProcess ? , / ?

!

+4
1

, DS9, , . , , , QProcess, QApplication:: exec(). , , QProcess DS9 , . , QProcess, DS9 , DS9.

:)

+1

All Articles