Results 1 to 8 of 8

Thread: QLineEdit text() crash - Qt3

  1. #1
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default QLineEdit text() crash - Qt3

    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 

  2. #2
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit text() crash - Qt3

    Use this:
    Qt Code:
    1. QString SaveFileName( ) { return m_pLineEdit->text() ;}
    To copy to clipboard, switch view to plain text mode 
    There is no reason to return strFileTest. More of that, the result of (strFileTest or m_pLineEdit->text()) is boolean, not string type.

  3. #3
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QLineEdit text() crash - Qt3

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit text() crash - Qt3

    Could you post the line in which you initialize m_pLineEdit?

  5. #5
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QLineEdit text() crash - Qt3

    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.

    Qt Code:
    1. void CMain1::ChosseFile()
    2. {
    3. QFileDialog * fileDlg = new QFileDialog(strPath,0,);
    4.  
    5. QString strFileName = fileDlg->selectedFile();
    6.  
    7. m_pLineEdit->setText (strFileName )
    8.  
    9. fileDlg->exec();
    10.  
    11. delete fileDlg;
    12.  
    13.  
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    How do I get text() value from m_pLineEdit.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit text() crash - Qt3

    Quote Originally Posted by user_mail07 View Post
    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?

  7. #7
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QLineEdit text() crash - Qt3

    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);
    }

  8. #8
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit text() crash - Qt3

    Try to check m_pDirEdit. Maybe m_pDirEdit == null?

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  3. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  4. Changing text colour of QLineEdit qss file
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 05:28
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.