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

Qt Code:
  1. class CMain1
  2. {
  3.  
  4. Q_OBJECT:
  5. ----
  6. public:
  7.  
  8.  
  9. QString SaveFileName( ) { return strFileTest or m_pLineEdit->text() ;}
  10.  
  11. public slots:
  12.  
  13. void ChooseFile();
  14.  
  15. private:
  16.  
  17. QPushButton * m_pPushButton;
  18. QLineEdit * m_pLineEdit;
  19. QString strFileTest;
  20. };
  21.  
  22. //I m connecting a push button clicked signal to ChooseFile slot :-
  23.  
  24. connect(m_pPushButton, SIGNAL(clicked()), SLOT(ChooseFile());
  25.  
  26. void CMain1::ChosseFile()
  27. {
  28. strFileTest = "SomeValue";
  29. m_pLineEdit->setText(strFileTest);
  30.  
  31. //Applications behaves as expected here ..sets the desired text to the line edit.
  32. }
  33.  
  34. Class CTestApp
  35. {
  36. Q_OBJECT:
  37.  
  38. public:
  39.  
  40. void GetAppName( ) ;
  41. }
  42.  
  43. void CTestApp::GetAppName()
  44. {
  45. CMain1 pMain;
  46.  
  47. QString str = pMain.SaveFileName();
  48.  
  49. // The problem is application crashed at SaveFileName() call.
  50. }
To copy to clipboard, switch view to plain text mode