PDA

View Full Version : Crash on connect



trust88
3rd May 2013, 14:32
Hi all,

I have a crash on connect in constructor


BuilderAppInstanceUI::BuilderAppInstanceUI(const Workflow &wf)
:ObserverAdapter(wf)
{
connect(Datasets, SIGNAL(currentItemChanged(QListWidgetItem*,QListWi dgetItem*)), Variables, SLOT(datasetChanged(QListWidgetItem*,QListWidgetIt em*)));
}


with
Datasets and
Variables two members of
BuilderAppInstanceUI:


class BuilderAppInstanceUI : public QWidget
, public ObserverAdapter
{
Q_OBJECT

public:
BuilderAppInstanceUI(const Workflow &workflow);
~BuilderAppInstanceUI();

void retranslateUi(QWidget *Form);
void setupUi(QWidget *Form);

QStackedWidget *stackedWidget;


BuilderAppListWidget *Datasets;
QTreeWidget *Variables;

private slots:
void datasetChanged(QListWidgetItem* current, QListWidgetItem* previous);

};



BuilderAppListWidget inherits from
QListWidget and as such can emit this signal
SIGNAL(currentItemChanged(QListWidgetItem*,QListWi dgetItem*))


class BuilderAppListWidget : public QListWidget
{
Q_OBJECT

public:
BuilderAppListWidget (QWidget* qwdgt = nullptr);
~BuilderAppListWidget (){};

void dragEnterEvent( QDragEnterEvent * event ) ;
void dragMoveEvent( QDragMoveEvent * event ) ;
void dropEvent( QDropEvent * event );
void keyReleaseEvent( QKeyEvent * event ) final ;

private:
BuilderAppInstanceUI* m_instance ;

};


Should I declare explicitly
currentItemChanged in body for
BuilderAppListWidget class ? If not, where does problem come from ?

Regards

Santosh Reddy
3rd May 2013, 16:46
datasetChanged is a slot of BuilderAppInstanceUI (not Variables), the connect should look like


connect(Datasets, SIGNAL(currentItemChanged(QListWidgetItem*,QListWi dgetItem*)), this, SLOT(datasetChanged(QListWidgetItem*,QListWidgetIt em*)));

d_stranz
3rd May 2013, 18:44
datasetChanged is a slot of BuilderAppInstanceUI (not Variables), the connect should look like

This wouldn't cause a crash, Qt would simply complain that the slot didn't exist.

However, if the code posted for the BuilderAppInstanceUI constructor is the whole thing, then the "Datasets" and "Variables" members have not been initialized prior to the connect() so they point to random locations in memory, not to actual instances of the widgets they represent. This would most certainly cause the crash as Qt attempts to resolve the meta-objects in the connect() method's execution.