Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. App crashing when I change the value of the slider it just crashes
Forum Updated to NodeBB v4.3 + New Features

App crashing when I change the value of the slider it just crashes

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 2 Posters 738 Views 2 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.
  • G Offline
    G Offline
    GGG03
    wrote on last edited by
    #1

    I want to rotate my item arround x-axis, so I have an slider to select the rotation. Everything is okay until I touch the slider. When I touch it, the app just crashes with an code 0. Can anyone help me?

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QVariant>
    #include <QQuickItem>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/gyroscope.qml")));
        ui->quickWidget->show();
        auto obj = ui->quickWidget->rootObject();
        connect(this, SIGNAL(on_open_clicked()), obj, SLOT(chargeObject()));
        connect(this, SIGNAL(on_print_clicked()), obj, SLOT(printValue()));
        connect(this, SIGNAL(changeValue(QVariant)), obj, SLOT(changeRotation(QVariant)));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_xSlider_valueChanged(int value)
    {
        emit changeValue(value);
    }
    

    gyroscope.qml

    import QtQuick.Controls 2.2
    import QtQuick.Dialogs 1.2
    import QtQuick 2.0
    import QtQuick.Scene3D 2.15
    import Qt3D.Core 2.5
    import Qt3D.Render 2.15
    import Qt3D.Input 2.12
    import Qt3D.Extras 2.15
    
    Rectangle
    {
        id: window
    
        FileDialog
        {
            id: fileDialog
            onAccepted:
            {
                sceneLoader.source = fileDialog.fileUrl
            }
        }
    
        Scene3D
        {
            anchors.fill: parent
            aspects: ["input", "logic"]
            cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
    
            Entity
            {
                id: sceneRoot
    
                Camera
                {
                    id: camera
                    projectionType: CameraLens.PerspectiveProjection
                    fieldOfView: 30
                    aspectRatio: 16/9
                    nearPlane : 0.1
                    farPlane : 1000.0
                    position: Qt.vector3d( 0.0, 0.0, -100.0 )
                    upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
                    viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
                }
    
                OrbitCameraController
                {
                    camera: camera
                }
    
                components:
                [
                    RenderSettings
                    {
                        activeFrameGraph: ForwardRenderer
                        {
                            clearColor: Qt.rgba(1, 1, 1, 1)
                            camera: camera
                        }
                    },
    
                    InputSettings
                    {
    
                    }
                ]
    
                Entity
                {
                    id: monkeyEntity
                    components:
                    [
                        SceneLoader
                        {
                            id: sceneLoader
                        },
    
                        Transform
                        {
                            id: transform
    
                            rotationY: 0;
                            rotationZ: 0;
                        }
                    ]
                }
    
                Axis
                {
                    id: axis
                }
    
            }
        }
    
        function printValue()
        {
            console.log(axis.value)
        }
    
        function chargeObject()
        {
            fileDialog.open()
        }
    
        function changeRotation(value)
        {
            transform.rotationX = value
        }
    }
    
    
    
    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Have you tried running the program under a debugger? That will probably reveal more about the location of the fault.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GGG03
        wrote on last edited by
        #3

        I used it and it reveals nothing. I know the error is in the transformation, but not exacly where-

        jeremy_kJ 1 Reply Last reply
        0
        • G GGG03

          I used it and it reveals nothing. I know the error is in the transformation, but not exacly where-

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          Is there a stack trace?

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GGG03
            wrote on last edited by
            #5

            what do you mean with stack? (I am new in this sorry)

            jeremy_kJ 1 Reply Last reply
            0
            • G GGG03

              what do you mean with stack? (I am new in this sorry)

              jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #6

              3a27448b-6c52-4045-8ce1-17a1db61c38e-image.png
              The pane at the bottom of this screen shot is a stack trace, indicating which functions are being called.

              Using an interactive debugger such as Qt Creator, we can click through the stack and examine the local variables in each frame. In this case, we can see that the char *s is a nullptr. Trying to access s[1] is invalid in this case, leading to the crash.

              Asking a question about code? http://eel.is/iso-c++/testcase/

              1 Reply Last reply
              1
              • G Offline
                G Offline
                GGG03
                wrote on last edited by
                #7

                Capture.JPG
                Do you mean this?
                The organization name and domain are not the problem because it worked before using that.

                jeremy_kJ 1 Reply Last reply
                0
                • G GGG03

                  Capture.JPG
                  Do you mean this?
                  The organization name and domain are not the problem because it worked before using that.

                  jeremy_kJ Offline
                  jeremy_kJ Offline
                  jeremy_k
                  wrote on last edited by
                  #8

                  @GGG03 said in App crashing when I change the value of the slider it just crashes:

                  Capture.JPG
                  Do you mean this?

                  I suspect the native code debugger will be more informative, but this might be enough. Is the transform object valid? Does it have a rotationX member? Is value valid to assign to it?

                  The organization name and domain are not the problem because it worked before using that.

                  Try eliminating that, and everything else that isn't essential to trigger the crash. Smaller programs make for easier problems to solve.

                  Asking a question about code? http://eel.is/iso-c++/testcase/

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    GGG03
                    wrote on last edited by
                    #9

                    In theory transform has it, it is the fuction https://doc.qt.io/qt-6/qt3dcore-qtransform.html#rotationX-prop
                    I tried to change the rotation value int for a float but it still crushes. I suspect the function is wrong, but I dont know why .

                    jeremy_kJ 1 Reply Last reply
                    0
                    • G GGG03

                      In theory transform has it, it is the fuction https://doc.qt.io/qt-6/qt3dcore-qtransform.html#rotationX-prop
                      I tried to change the rotation value int for a float but it still crushes. I suspect the function is wrong, but I dont know why .

                      jeremy_kJ Offline
                      jeremy_kJ Offline
                      jeremy_k
                      wrote on last edited by
                      #10

                      @GGG03 said in App crashing when I change the value of the slider it just crashes:

                      In theory transform has it

                      Use the debugger to validate that theory. Look at the values of all objects involved.
                      Print statements also work.

                      function changeRotation(value)
                      {
                          console.log("transform =", transform);
                          console.log("transform.rotationX =", transform.rotationX);
                          console.log("value =", value);
                          transform.rotationX = value;
                          console.log("assignment did not crash");
                      }

                      Asking a question about code? http://eel.is/iso-c++/testcase/

                      1 Reply Last reply
                      1
                      • G Offline
                        G Offline
                        GGG03
                        wrote on last edited by
                        #11

                        I've done it. It is working. Thanks

                        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