Search code examples
c++qtqlineedit

QLineEdit.text() function makes my program crash, but only when it's in a slot


quick Explanation, im still in HS and trying to put together a little project, basically its some kind of messenger app using our school's servers.

Of course, for that, you need a login window, with account management and stuff. The account management part is already done, leaving only the part where i put everything together, connecting the buttons to actions and etc.

So i made slots for that :

Slots :

The problem is that my whole app crashes as soon as i try to read the text in the QLineEdits from the window's slot

(m_nickname and m_password are the two QLineEdit where the username and password are typed in) (m_login and m_signup are the two buttons to login and signup)

Also, here is my whole class definition if that helps : .cpp .h

Thanks in advance to anyone who tries to help me :-)


Solution

  • It crash's cause of segmentation fault. you didn't assign an address for this two QLineEdits. what you actually did in constructor is defining another QLineEdit m_nickname and m_password and your class member variable did not locate in memmory
    change your constructor where you define these QLineEdits like this:

    instead of

    QLineEdit *m_nickname = new QLineEdit();
    

    write

    m_nickname = new QLineEdit();
    

    and instead of

    QLineEdit *m_password = new QLineEdit();
    

    write

    m_password = new QLineEdit();