0

I want to start my QT6 Application, but got exit code 139 (interrupted by signal 11: SIGSEGV). Login extends QMainWindow with the following code in the main.cpp:

#include <QApplication>
#include <QPushButton>
#include "Login.h"
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    auto login = new Login();
    a.setActiveWindow(login);
    login->show();
    return a.exec();//QApplication::exec();
}

Edit: Adding Code of my Login.h and Login.cpp to provide minimal working example. My Login.h:

#ifndef RESTCLIENT_LOGIN_H
#define RESTCLIENT_LOGIN_H

#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include "QMainWindow"


QT_BEGIN_NAMESPACE
namespace Ui { class Login; }
QT_END_NAMESPACE

class Login : public QMainWindow {
Q_OBJECT

QPushButton * loginButton;
QLineEdit * passwordInput;
QLineEdit * usernameInput;

public slots:
    void buttonPressed();

public:
    explicit Login(QWidget *parent = nullptr);

    ~Login() override;

private:
    Ui::Login *ui;
};

#endif //RESTCLIENT_LOGIN_H

And Login.cpp:

#include "Login.h"
#include "ui_Login.h"

Login::Login(QWidget *parent) :
        QMainWindow(parent), ui(new Ui::Login) {
    ui->setupUi(this);
    QObject::connect(loginButton, &QPushButton::clicked, this, &Login::buttonPressed);
    this ->setCentralWidget(new QWidget(this));
}

Login::~Login() {
    delete ui;
}

void Login::buttonPressed() {
    //todo process login
}

There is no more errors when running it, as far as I undestand it, there is no problem with finding it.

My Login GUI is very simple, I'm connecting my loginButton to the buttonPressed method in the Login.cpp, but that should be fine. My Login.h is basically method definiton and definition of the QT elements.

Some help would be very nice, cause I can't find any usefull stuff about this (As you see, I'm new to c++ and QT)

Editi 2: my ui_login.h:

/********************************************************************************
** Form generated from reading UI file 'Login.ui'
**
** Created by: Qt User Interface Compiler version 6.2.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_LOGIN_H
#define UI_LOGIN_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Login
{
public:
    QLabel *label;
    QLabel *label_2;
    QLineEdit *usernameInput;
    QLineEdit *passwordInput;
    QPushButton *loginButton;

    void setupUi(QWidget *Login)
    {
        if (Login->objectName().isEmpty())
            Login->setObjectName(QString::fromUtf8("Login"));
        Login->resize(1216, 835);
        label = new QLabel(Login);
        label->setObjectName(QString::fromUtf8("label"));
        label->setGeometry(QRect(230, 180, 121, 51));
        label->setLineWidth(2);
        label_2 = new QLabel(Login);
        label_2->setObjectName(QString::fromUtf8("label_2"));
        label_2->setGeometry(QRect(220, 340, 111, 41));
        usernameInput = new QLineEdit(Login);
        usernameInput->setObjectName(QString::fromUtf8("usernameInput"));
        usernameInput->setGeometry(QRect(490, 190, 141, 51));
        passwordInput = new QLineEdit(Login);
        passwordInput->setObjectName(QString::fromUtf8("passwordInput"));
        passwordInput->setGeometry(QRect(490, 360, 151, 41));
        loginButton = new QPushButton(Login);
        loginButton->setObjectName(QString::fromUtf8("loginButton"));
        loginButton->setGeometry(QRect(520, 480, 88, 34));

        retranslateUi(Login);
        QObject::connect(loginButton, &QPushButton::clicked, loginButton, qOverload<>(&QPushButton::click));

        QMetaObject::connectSlotsByName(Login);
    } // setupUi

    void retranslateUi(QWidget *Login)
    {
        Login->setWindowTitle(QCoreApplication::translate("Login", "Login", nullptr));
        label->setText(QCoreApplication::translate("Login", "Username:", nullptr));
        label_2->setText(QCoreApplication::translate("Login", "Password:", nullptr));
        loginButton->setText(QCoreApplication::translate("Login", "Login", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Login: public Ui_Login {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_LOGIN_H
  • 2
    Please edit your question to provide a [mcve]. The code shown looks fine so the problem is almost certainly with your `Login` implementation. – G.M. Apr 29 '22 at 13:59
  • It looks like your code crashes (SISEGV means segmentation fault) inside your Login class which should be somthing like a window – Marco Beninca Apr 29 '22 at 14:11
  • I've added a minimal working example – saltycoder815 Apr 29 '22 at 14:12
  • 1
    Where do you initialize `loginButton`? – G.M. Apr 29 '22 at 14:16
  • I'm now doing: loginButton = this->findChild("loginButton"); But pressing button causes segmentation fault – saltycoder815 Apr 29 '22 at 14:51
  • when there is a segmentation fault, run the code in a debugger, and check the the variables at the location. typically some pointer is `nullptr` which shouldn't be – codeling Apr 29 '22 at 15:17
  • What is `loginButton` supposed to point to? Do you have a `QPushButton` name `loginButton` in your `UI` file? If so you probably want something like `ui-> loginButton` instead of a dedicated member variable. Please edit the question to show your `UI` file. – G.M. Apr 29 '22 at 17:30
  • I think we need to see your generated ui_login.h. I mean to me it looks strange that your buttons etc. are in Login.h. They should be normally in the generated ui_login.h (it is created by qt "designer", afaik). – JenyaKh Apr 29 '22 at 17:43
  • added the code of ui_login.h I tried to change the fields in login.h to use ui->loginButton, but the segmentation fault still exists after clicking the button, refering to struct FunctorCall, List, SlotRet – saltycoder815 Apr 30 '22 at 07:07

0 Answers0