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. The inferior stopped because it triggered an exception

The inferior stopped because it triggered an exception

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 726 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.
  • S Offline
    S Offline
    Sailanarmo
    wrote on last edited by Sailanarmo
    #1

    A follow up on my last unsolved post. I have traced the problem down to the fact that my program crashes when I try to update my slider, however, this only happens when I try to update the ui's slider. For example if I run the following code:

    TestController::TestController(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::TestController),
        newSlider(*ui->horizontalSlider),
        newTextBox(*ui->spinBox),
        controller(newSlider,newTextBox,newTestClass)
    {
        ui->setupUi(this);
    
        QSlider *slider = new QSlider;
        QSlider& ples = *slider;
        ples.setValue(20);
        std::cout << ples.value() << std::endl;
    
        Slider *slider2 = new Slider;
        Slider& test = *slider2;
        test.setValue(30);
        std::cout << test.value() << std::endl;
    
    }
    

    This will compile and give me 20 and 30 as expected when the program launches. However, if I even touch the slider on my gui, or my text box, the program immediately crashes and I am given the error:

    The inferior stopped because it triggered an exception.
    
    Stopped in thread 0 by: Exception at ... : read access violation at ..., flags=0x0(first chance).
    

    I am confused as to why this:

    Slider& uiSlider = *ui->horizontalSlider;
    uiSlider.setValue(35);
    std::cout << uiSlider.value() << std::endl;
    

    crashes the program entirely since ui->horizontalSlider has been promoted to the class Slider. All my header file:

    class Slider : public QSlider
    {
        Q_OBJECT
    public:
        Slider(QWidget *parent = nullptr);
    
        void updateValue(int value) { this->setValue(value);}
        int get() const { return this->value(); }
    };
    

    Does is update the value of the slider and get the value of the slider. And honestly, the stack trace doesn't tell me much either which is also super confusing to me:

    0_1557182325195_debug.png

    Because at this point in the code I am not even calling updateValue(). I'm really stuck and I really don't know what to do from here. Any help would be greatly appreciated.[0_1557248297459_Minimal.zip](Uploading 100%)

    EDIT: Apparently Slider &uiSlider = *ui->horizontalSlider; does not break the code. It was a call in my controller that was causing it to break.

    aha_1980A 1 Reply Last reply
    0
    • S Sailanarmo

      A follow up on my last unsolved post. I have traced the problem down to the fact that my program crashes when I try to update my slider, however, this only happens when I try to update the ui's slider. For example if I run the following code:

      TestController::TestController(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::TestController),
          newSlider(*ui->horizontalSlider),
          newTextBox(*ui->spinBox),
          controller(newSlider,newTextBox,newTestClass)
      {
          ui->setupUi(this);
      
          QSlider *slider = new QSlider;
          QSlider& ples = *slider;
          ples.setValue(20);
          std::cout << ples.value() << std::endl;
      
          Slider *slider2 = new Slider;
          Slider& test = *slider2;
          test.setValue(30);
          std::cout << test.value() << std::endl;
      
      }
      

      This will compile and give me 20 and 30 as expected when the program launches. However, if I even touch the slider on my gui, or my text box, the program immediately crashes and I am given the error:

      The inferior stopped because it triggered an exception.
      
      Stopped in thread 0 by: Exception at ... : read access violation at ..., flags=0x0(first chance).
      

      I am confused as to why this:

      Slider& uiSlider = *ui->horizontalSlider;
      uiSlider.setValue(35);
      std::cout << uiSlider.value() << std::endl;
      

      crashes the program entirely since ui->horizontalSlider has been promoted to the class Slider. All my header file:

      class Slider : public QSlider
      {
          Q_OBJECT
      public:
          Slider(QWidget *parent = nullptr);
      
          void updateValue(int value) { this->setValue(value);}
          int get() const { return this->value(); }
      };
      

      Does is update the value of the slider and get the value of the slider. And honestly, the stack trace doesn't tell me much either which is also super confusing to me:

      0_1557182325195_debug.png

      Because at this point in the code I am not even calling updateValue(). I'm really stuck and I really don't know what to do from here. Any help would be greatly appreciated.[0_1557248297459_Minimal.zip](Uploading 100%)

      EDIT: Apparently Slider &uiSlider = *ui->horizontalSlider; does not break the code. It was a call in my controller that was causing it to break.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      @Sailanarmo

      A follow up on my last unsolved post.

      So why are you creating a new post? This is bad practise. you could have easily provided the new information there.

      That said, if you can upload your (minlmal) compile- and executable code somewhere, we could just try it.

      Regards

      Edit:

      Slider& uiSlider = *ui->horizontalSlider;

      What is that? Please elaborate.

      Qt has to stay free or it will die.

      1 Reply Last reply
      4
      • S Offline
        S Offline
        Sailanarmo
        wrote on last edited by Sailanarmo
        #3

        @aha_1980

        I'm trying to upload the .zip file but I do not have enough privileges to do so. So I have uploaded it to my github account. You will need a C++17 Compiler in order to run the example by the way. This is the best I can do since I don't have the privileges to upload a .zip file. Or, I can copy paste all of the code including the ui file, please let me know which is the easiest.

        Now to elaborate,

        my Controller class takes classes by reference and not by pointers, so I turn the pointer into a reference so I can actually perform the task I am trying to accomplish.

        Basically, it is one massive sync at a time, I create a Controller<Slider,SpinBox,CustomClass> controller;. I then can set all of their values by calling controller.setValues(35); Which then calls Slider's, SpinBox's, and CustomClass' updateValue function which will call their respective setters. In this case,
        this->setValue(int) for the Slider and the SpinBox, and setVal(int) for CustomClass. So the reason I do that, is so I can pass the reference to the horizontal slider into my controller class. However, as you will see in my header file I have:

        Slider &newSlider;
        Controller<Slider> controller;
        

        I then initialize them in the .cpp file by:

        newSlider(*ui->horizontalSlider);
        controller(newSlider);
        

        But, this breaks whenever I try to call controller.setValues(int);. Or if I try to call newSlider.setValue(int). However, if in the constructor I do something like:

        Slider &test = *ui->horizontalSlider;
        test.setValue(int);
        std::cout << ui->horizontalslider->value() << std::endl;
        

        It actually doesn't break. Which confuses me a lot.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sailanarmo
          wrote on last edited by
          #4

          SOLVED

          After conversing with someone, it was determined that the ui->horizontalSlider was not yet initialized so I was not pointing to anything. To solve this, I then created a Slider pointer and a Controller pointer. I then initialized them in the scope of the constructor and now everything works as desired.

          1 Reply Last reply
          1

          • Login

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