PDA

View Full Version : QLineEdit text() crash - Qt3



user_mail07
9th June 2008, 08:06
Hi,

I am getting a crash while trying to get text() from QLineEdit. I am setting a text on lineEdit in connected slot. However when I tried to get back that text I am getting crash.
I am using Qt3 setText() method of QlineEdit to set the text to the lineEdit.

Here's the code snippet:

I created two classes Class CMain1 and Class CTestApp


class CMain1
{

Q_OBJECT:
----
public:


QString SaveFileName( ) { return strFileTest or m_pLineEdit->text() ;}

public slots:

void ChooseFile();

private:

QPushButton * m_pPushButton;
QLineEdit * m_pLineEdit;
QString strFileTest;
};

//I m connecting a push button clicked signal to ChooseFile slot :-

connect(m_pPushButton, SIGNAL(clicked()), SLOT(ChooseFile());

void CMain1::ChosseFile()
{
strFileTest = "SomeValue";
m_pLineEdit->setText(strFileTest);

//Applications behaves as expected here ..sets the desired text to the line edit.
}

Class CTestApp
{
Q_OBJECT:

public:

void GetAppName( ) ;
}

void CTestApp::GetAppName()
{
CMain1 pMain;

QString str = pMain.SaveFileName();

// The problem is application crashed at SaveFileName() call.
}

roxton
9th June 2008, 11:00
Use this:


QString SaveFileName( ) { return m_pLineEdit->text() ;}

There is no reason to return strFileTest. More of that, the result of (strFileTest or m_pLineEdit->text()) is boolean, not string type.

user_mail07
9th June 2008, 15:07
Thanks roxton for replying . But It still crash at text() method while using following statement. I did not use or in my code as boolean. I just putt'ed here to tell that I tried with both statements.

QString SaveFileName( ) { return m_pLineEdit->text() ;}

Still I have no clue while I can no get value back from lineEdit. I am thinking may be something to do with slot. Because I am setting the text in slot.

jacek
10th June 2008, 00:52
Could you post the line in which you initialize m_pLineEdit?

user_mail07
10th June 2008, 01:23
will explain the problem in detail. What I am doing is selecting a file from QFileDialog and then displaying that filename with path to the m_pLineEdit. When I click browse push button and it will emit a slot ChooseFile( ) and then I create a filedialog ,browse the desired file and then I set a selectedFile to the m_pLineEdit.

Here every thing I have been doing in ChosseFile( ) slot that is browse slot .

m_pLineEdit I have loading from UI desinger file using child ( const char * objName, const char * inheritsClass = 0) method.


void CMain1::ChosseFile()
{
QFileDialog * fileDlg = new QFileDialog(strPath,0,);

QString strFileName = fileDlg->selectedFile();

m_pLineEdit->setText (strFileName )

fileDlg->exec();

delete fileDlg;



}

How do I get text() value from m_pLineEdit.

jacek
10th June 2008, 02:04
m_pLineEdit I have loading from UI desinger file using child ( const char * objName, const char * inheritsClass = 0) method.
Could you post the line that does this?

user_mail07
10th June 2008, 02:29
Here is the exact line:

m_pDirEdit = (QLineEdit *)CreateChildDlg(myMainDlg, "lineEdit");

Implemention of CreateChildDlg:

QObject * CMainUIDialog::CreateChildDlg( QObject * parentObject, QString strChild )
{
if(parentObject)
return(parentObject->child (strChild, 0, TRUE ));
else
return(NULL);
}

roxton
10th June 2008, 09:42
Try to check m_pDirEdit. Maybe m_pDirEdit == null?