Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting segmentation fault when using Ui_LoginScreen().lineEdit->text();

Getting segmentation fault when using Ui_LoginScreen().lineEdit->text();

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    volkish
    wrote on last edited by
    #1

    Hello I am stuck and cannot continue further.

    My application is about to read a database and then compare the input from a login interface where the user types his password and username. I have so far designed the login interface but I keep getting this segmentation fault whenever I try to run the code? I just want to compare the input with the values from the database. Why do I get this segmentation error and how can I solve it ?
    Here is my code

      #include "LoginScreen.h"
      #include <QApplication>
      #include <QMessageBox>
    
    
      LoginScreen::LoginScreen(){
    
        widget.setupUi(this);
        connect(widget.pushButton, SIGNAL(clicked()),this, SLOT(clickedSlot()));
    
      }
    
      LoginScreen::~LoginScreen(){}
    
       void LoginScreen::clickedSlot(){
      
       QMessageBox msgBox;
       QString usernameFromInterface,passwordFromInterface;
        
       usernameFromInterface = Ui_LoginScreen().lineEdit->text();//ERROR OCCURS HERE
       }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Your ui_loginscreen object may be null. Check it.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • V Offline
        V Offline
        volkish
        wrote on last edited by
        #3

        How do I check if it is null ? This is the body that is generated. Should I declare it somewhere in the main maybe??
        [code]

                /********************************************************************************
                ** Form generated from reading UI file 'LoginScreen.ui'
                **
                ** Created by: Qt User Interface Compiler version 5.5.1
                **
                ** WARNING! All changes made in this file will be lost when recompiling UI file!
                ********************************************************************************/
        
                #ifndef UI_LOGINSCREEN_H
                #define UI_LOGINSCREEN_H
        
                #include <QtCore/QVariant>
                #include <QtWidgets/QAction>
                #include <QtWidgets/QApplication>
                #include <QtWidgets/QButtonGroup>
                #include <QtWidgets/QDialog>
                #include <QtWidgets/QHeaderView>
                #include <QtWidgets/QLabel>
                #include <QtWidgets/QLineEdit>
                #include <QtWidgets/QPushButton>
        
                QT_BEGIN_NAMESPACE
        
                class Ui_LoginScreen
                {
                public:
                    QLineEdit *lineEdit;
                    QLineEdit *lineEdit_2;
                    QLabel *label;
                    QLabel *label_2;
                    QPushButton *pushButton;
                    QLabel *label_3;
        
                    void setupUi(QDialog *LoginScreen)
                    {
                        if (LoginScreen->objectName().isEmpty())
                            LoginScreen->setObjectName(QStringLiteral("LoginScreen"));
                        LoginScreen->resize(693, 429);
                        lineEdit = new QLineEdit(LoginScreen);
                        lineEdit->setObjectName(QStringLiteral("lineEdit"));
                        lineEdit->setGeometry(QRect(270, 120, 113, 20));
                        lineEdit_2 = new QLineEdit(LoginScreen);
                        lineEdit_2->setObjectName(QStringLiteral("lineEdit_2"));
                        lineEdit_2->setGeometry(QRect(270, 170, 113, 20));
                        lineEdit_2->setEchoMode(QLineEdit::Password);
                        label = new QLabel(LoginScreen);
                        label->setObjectName(QStringLiteral("label"));
                        label->setGeometry(QRect(270, 100, 47, 13));
                        label_2 = new QLabel(LoginScreen);
                        label_2->setObjectName(QStringLiteral("label_2"));
                        label_2->setGeometry(QRect(270, 150, 47, 13));
                        pushButton = new QPushButton(LoginScreen);
                        pushButton->setObjectName(QStringLiteral("pushButton"));
                        pushButton->setGeometry(QRect(290, 210, 75, 23));
                        pushButton->setCheckable(true);
                        label_3 = new QLabel(LoginScreen);
                        label_3->setObjectName(QStringLiteral("label_3"));
                        label_3->setGeometry(QRect(270, 30, 141, 61));
                        label_3->setTextFormat(Qt::RichText);
                        label_3->setMargin(5);
                        label_3->setIndent(5);
        
                        retranslateUi(LoginScreen);
                
                        QMetaObject::connectSlotsByName(LoginScreen);
                    } // setupUi
        
                    void retranslateUi(QDialog *LoginScreen)
                    {
                        LoginScreen->setWindowTitle(QApplication::translate("LoginScreen", "LoginScreen", 0));
                        label->setText(QApplication::translate("LoginScreen", "Username", 0));
                        label_2->setText(QApplication::translate("LoginScreen", "Password", 0));
                        pushButton->setText(QApplication::translate("LoginScreen", "Ok", 0));
                        label_3->setText(QApplication::translate("LoginScreen", "Welcome to SEP", 0));
                    } // retranslateUi
                
                };
        
                namespace Ui {
                    class LoginScreen: public Ui_LoginScreen {};
                } // namespace Ui
        
                QT_END_NAMESPACE
        
                #endif // UI_LOGINSCREEN_H
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Because you're code is wrong. you are instantiating an object of type Ui_LoginScreen without initialising it. But even if you did you would not get the value you expect.

          I take it that your widget variable type is Ui_LoginScreen, correct ? If so, you should use it to retrieve the text from the lineEdit widget.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved