PDA

View Full Version : QLineEdit Segmentation fault (core dumped)



cristiano
12th October 2006, 02:14
Hello,

I have a QLineEdit in the Form1, would like to write in a method of the Form2 in the QLineEdit of the Form1.

I am trying something thus more I get the following when clic error in the button of Form2.

Form1.h

/*================================================= ==*/

class Form1 : public QDialog
{
Q_OBJECT

public:
Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Form1();

QLineEdit* lineEdit1;
QPushButton* btnOK;

public slots:
virtual void test();

};

/*================================================= ==*/


Form2.h


/*================================================= ==*/
#include <Form1.h>

class Form2 : public QDialog
{
Q_OBJECT

public:
Form2( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );

~Form2();

QLineEdit* lineEdit2;
QPushButton* btnOK;

public slots:
virtual void sendLine();

private:
Form1 *ParentForm; /* direct access to Form1*/
};
/*================================================= ==*/


Form2.cpp


/*================================================= ==*/
Form2::Form2( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )

{
/* Direct access to Form1*/
ParentForm = (Form1*) parent ;
.....
.....

void Form2::sendLine()
{
QString P = tr("It sends text to the QLineEdit of the Form1");
ParentForm->lineEdit1->setText(P);
}
/*================================================= ==*/


When I call this method sendLine () happens:

--> Segmentation fault (core dumped)

Somebody has some idea of as I can make this !!!

Cris.

munna
12th October 2006, 05:18
Are you sure both form1 and lineEdit1 have been initialized before calling sendLine() ?