terminated by signal SIGSEGV (Address boundary error)
-
Newbie to Qt/C++ here. My code builds successfully but when I run my newly compiled application, I get an address boundary error. what part of my code is causing it?
// main.cpp #include "mainwindow.h" #include <QApplication> #include <QLocale> #include <QTranslator> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); for (const QString &locale : uiLanguages) { const QString baseName = "Hello_Qt_" + QLocale(locale).name(); if (translator.load(":/i18n/" + baseName)) { a.installTranslator(&translator); break; } } MainWindow mainWindow; mainWindow.show(); return a.exec(); }// mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QPushButton> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void handleButton(); private: QPushButton *pressMeButton; Ui::MainWindow *ui; }; #endif// mainwindow.cpp #include "mainwindow.h" #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); connect(pressMeButton, &QPushButton::released, this, &MainWindow::handleButton); } MainWindow::~MainWindow() { delete ui; } void MainWindow::handleButton() { } -
@13character5
Debug your program and check where it crashes -
how do I debug with QtCreator?
-
how do I debug with QtCreator?
Run a debugger (F5) and step through your app until you face the crash. It will stop and show the last call
Edit:
You don't actually create your button in your constructor. You just declared the variable and tried to connect to it. At this point, there is no pushbutton then.
Instantiate your
QPushButtonand it should work.
(AFAICS this might be the cause of your crash, unless there is something else somewhere in your code that you are not showing) -
how do i Instantiate a QPushButton
-
how do i Instantiate a QPushButton
@13character5 said in terminated by signal SIGSEGV (Address boundary error):
how do i Instantiate a QPushButton
You should learn C++ before trying Qt: https://www.geeksforgeeks.org/cpp/c-classes-and-objects/
-
how do i Instantiate a QPushButton
@13character5
As the others have said. But since you seem to have used Qt Designer to design some interface (right?) I suspect/wonder whether you are trying to access aQPushButtonwhich you already put there? Perhaps named by you at the timepressMeButton? If so it will be inside theuiobject, likeui->pressMeButton. And you won't want/need your own (currently uninitialized, hence the crash)QPushButton *pressMeButtonas a class variable?