Both objects appear on the form, for temp1 works as a slot createNewSet () and connect. For _firstSet, neither works. Fields class Cows:

class Cows : public QMainWindow { Q_OBJECT public: Cows(QWidget *parent = 0); ~Cows(); private: Ui::CowsClass ui; estimatedSet* _firstSet; QList<estimatedSet*> * _otherSets; }; 

In the constructor of the Cows class, I initialize the objects of the estimatedSet class:

 Cows::Cows(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); estimatedSet * temp1 = new estimatedSet(this); estimatedSet temp2 = new estimatedSet(this); _firstSet = &temp2; temp1.last()->createNewSet(); connect(temp1, SIGNAL(fillComplete()), this, SLOT(prepareShift())); } 
  • 2
    How did you compile the code with temp2 initialization? - αλεχολυτ
  • @alexolut, the compiler does not give any error. In the debugger, I see the created object. I work with qt via vs-addin in vs 2015. - user183009
  • Here is a typo: estimatedSet temp2 = new estimatedSet (this); (temp2 is a local variable, not a pointer.) Accordingly, after leaving the constructor, the object pointed to by _firstSet is already destroyed. - Chorkov
  • And where are the connections of temp2 signals to slots? - aleks.andr

1 answer 1

temp2 is on the stack. When the output from the Cows constructor temp2 , the temp2 object will be automatically destroyed => disconnects of all its signals will occur.