Тема: Сигнал SIGSEGV segmentation fault
Створив проект у QT, суть його проста. У вікні є 2 таблиці. За замовчуванням в них всього 1 елемент, але це можливо налаштувати за допомогою відповідних спінбоксів в нижній частині вікна. В одну таблицю вводится массив чисел і по настиканні кнопки программа має перевірити кожний елемент на кратність. Якщо елемент кратний - вона виводить його у відповідній комірці другої таблиці, а якщо ні то у відповідну комірку вводить текст "Nan" але якщо я залишаю всього 1 елемент то программа не працює взагалі (запускається, але нічого не виводится), а якщо я якось змінюю розмірність то при спробі пропустити программу через відладник отримав повідомлення:
Підпроцес зупинено, оскільки він отримав сигнал від операційної системи.
Назва сигналу: SIGSEGV
Значення сигналу: Segmentation fault
Порившись у гуглі я виявив що це виникає коли программа звертається до сегменту пам'яті, до якого не має доступу.
Код:
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  MainWindow w;
  w.show();
  return a.exec();
}mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
      , ui(new Ui::MainWindow)
{
  ui->setupUi(this);
}
MainWindow::~MainWindow()
{
  delete ui;
}
void MainWindow::on_spbSize_valueChanged(int InputArrSize)
{
  InputArrSize = ui->spbSize->value();
  if(InputArrSize == 1)
  {
    ui->lblYCoord->setDisabled(1);
    ui->spbYCoord->setDisabled(1);
  }
  else
  {
    ui->lblYCoord->setDisabled(0);
    ui->spbYCoord->setDisabled(0);
  }
}
void MainWindow::on_spbXCoord_valueChanged(int RowCount)
{
  ui->TBLInput->setRowCount(RowCount);
  ui->TBLOutput->setRowCount(RowCount);
}
void MainWindow::on_spbYCoord_valueChanged(int ColumnCount)
{
  ui->TBLInput->setColumnCount(ColumnCount);
  ui->TBLOutput->setColumnCount(ColumnCount);
}
void MainWindow::on_PBTArrayCheck_clicked()
{
  int RowCount, ColumnCount;
  RowCount = ui->TBLInput->rowCount();
  ColumnCount = ui->TBLInput->columnCount();
  int n = 1;
  int i = 1;
  while (n<RowCount || i<ColumnCount)
  {
    QString buffer;
    buffer = ui->TBLInput->item(n,i)->text();
    int buff = buffer.toInt();
    if (buff%2==0)
    {
      ui->TBLOutput->item(n,i)->setText(buffer);
    }
    else
    {
      ui->TBLOutput->item(n,i)->setText("Nan");
    }
    if(n<RowCount)
    {
      n++;
    }
    if(n=RowCount, i<ColumnCount)
    {
      n=1;
      i++;
    }
    int Progress100 = RowCount*ColumnCount;
    int CurrentProgress = 0;
    CurrentProgress++;
    int ProgressValue = CurrentProgress/Progress100 * 100;
    ui->PBArrayCheck->setValue(ProgressValue);
  };
}mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
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 on_spbSize_valueChanged(int arg1);
               void on_spbXCoord_valueChanged(int arg1);
               void on_spbYCoord_valueChanged(int arg1);
               void on_PBTArrayCheck_clicked();
             private:
  Ui::MainWindow *ui;
};
#endif // MAINWINDOW_Hmainwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>994</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QTableWidget" name="TBLInput">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>40</y>
      <width>431</width>
      <height>371</height>
     </rect>
    </property>
    <property name="inputMethodHints">
     <set>Qt::ImhDigitsOnly</set>
    </property>
    <row>
     <property name="text">
      <string>1</string>
     </property>
    </row>
    <column>
     <property name="text">
      <string>1</string>
     </property>
    </column>
   </widget>
   <widget class="QLabel" name="lblInput">
    <property name="geometry">
     <rect>
      <x>140</x>
      <y>10</y>
      <width>131</width>
      <height>20</height>
     </rect>
    </property>
    <property name="text">
     <string>Входящий массив</string>
    </property>
   </widget>
   <widget class="QTableWidget" name="TBLOutput">
    <property name="enabled">
     <bool>false</bool>
    </property>
    <property name="geometry">
     <rect>
      <x>480</x>
      <y>40</y>
      <width>431</width>
      <height>371</height>
     </rect>
    </property>
    <property name="inputMethodHints">
     <set>Qt::ImhNone</set>
    </property>
    <row>
     <property name="text">
      <string>1</string>
     </property>
    </row>
    <column>
     <property name="text">
      <string>1</string>
     </property>
    </column>
   </widget>
   <widget class="QLabel" name="lblOutput">
    <property name="geometry">
     <rect>
      <x>610</x>
      <y>10</y>
      <width>141</width>
      <height>20</height>
     </rect>
    </property>
    <property name="text">
     <string>Исходящий массив</string>
    </property>
   </widget>
   <widget class="QSpinBox" name="spbSize">
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>430</y>
      <width>42</width>
      <height>26</height>
     </rect>
    </property>
    <property name="minimum">
     <number>1</number>
    </property>
    <property name="maximum">
     <number>2</number>
    </property>
   </widget>
   <widget class="QLabel" name="lblSize">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>430</y>
      <width>161</width>
      <height>20</height>
     </rect>
    </property>
    <property name="text">
     <string>Размерность массива</string>
    </property>
   </widget>
   <widget class="QSpinBox" name="spbXCoord">
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>460</y>
      <width>42</width>
      <height>26</height>
     </rect>
    </property>
    <property name="minimum">
     <number>1</number>
    </property>
   </widget>
   <widget class="QSpinBox" name="spbYCoord">
    <property name="enabled">
     <bool>false</bool>
    </property>
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>490</y>
      <width>42</width>
      <height>26</height>
     </rect>
    </property>
    <property name="minimum">
     <number>1</number>
    </property>
   </widget>
   <widget class="QLabel" name="lblXCoord">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>460</y>
      <width>161</width>
      <height>20</height>
     </rect>
    </property>
    <property name="text">
     <string>1 Координата</string>
    </property>
   </widget>
   <widget class="QLabel" name="lblYCoord">
    <property name="enabled">
     <bool>false</bool>
    </property>
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>490</y>
      <width>161</width>
      <height>20</height>
     </rect>
    </property>
    <property name="text">
     <string>2 Координата</string>
    </property>
   </widget>
   <widget class="QPushButton" name="PBTArrayCheck">
    <property name="geometry">
     <rect>
      <x>420</x>
      <y>490</y>
      <width>231</width>
      <height>29</height>
     </rect>
    </property>
    <property name="text">
     <string>Проверить массив на четность</string>
    </property>
   </widget>
   <widget class="QProgressBar" name="PBArrayCheck">
    <property name="geometry">
     <rect>
      <x>320</x>
      <y>450</y>
      <width>461</width>
      <height>23</height>
     </rect>
    </property>
    <property name="inputMethodHints">
     <set>Qt::ImhNone</set>
    </property>
    <property name="value">
     <number>0</number>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>994</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>