Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PROBLEM TO SIGNALS AND SLOTS



  • I Create A custom widget Class in main window and i try to connect a slider from mainwindow to a function in Qustom class. App starts correctly but when i move the slider it gets The program has unexpectedly finished.Screenshot_8.png


  • Lifetime Qt Champion

    @Giakara said in PROBLEM TO SIGNALS AND SLOTS:

    The program has unexpectedly finished

    So, did you use the debugger to see where and why it crashes?
    Is "window" a valid pointer?

    Also, please post code as text, not pictures.



  • The debugger shows an error about qtcreatordbext.dll not found

    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; class WindowWidget; }
    QT_END_NAMESPACE

    class WindowWidget : public QWidget {
    Q_OBJECT
    public:
    WindowWidget(QWidget *parent = nullptr) {

    //code//

           fast::SurfaceExtraction::pointer mSurfaceExtraction = fast::SurfaceExtraction::New();
           mSurfaceExtraction->setInputConnection(mSmoothing->getOutputPort());
           mSurfaceExtraction->setThreshold(0);
    
        };
        ~WindowWidget() {
            fast::Reporter::info() << "Trying to stop computation thread" << fast::Reporter::end();
            if(mThread != NULL) {
                mThread->stop();
                delete mThread;
                mThread = NULL;
            }
            fast::Reporter::info() << "Computation thread stopped" << fast::Reporter::end();
        };
    public slots:
        }
        void updateThreshold(int value){
    
            mSurfaceExtraction->setThreshold(value);
    
        };
    
    private:
        fast::SurfaceExtraction::pointer mSurfaceExtraction;
        fast::ComputationThread* mThread;
        fast::View* mView;
        fast::GaussianSmoothingFilter::pointer mSmoothing;
    

    };
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    private slots:

    void on_slider_valueChanged(int value);
    

    private:
    Ui::MainWindow *ui;
    WindowWidget *window;
    };

    cpp

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
    ui(new Ui::MainWindow),window(new WindowWidget)
    {

    ui->setupUi(this);
    ui->verticalLayout->addWidget(window);
    //connect(ui->slider, &QSlider::valueChanged, std::bind(&WindowWidget::updateThreshold, this, std::placeholders::_1));
    

    }

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

    void MainWindow::on_slider_valueChanged(int value)
    {

    window->updateThreshold(value);

    }

    this is my code if i create o slider inside my Window it works (I m new to QT)


  • Lifetime Qt Champion

    @Giakara said in PROBLEM TO SIGNALS AND SLOTS:

    void updateThreshold(int value){

        mSurfaceExtraction->setThreshold(value);
    
    };
    

    Please check all your pointers and fix your debugger - people here are not debuggers to analize crashes in your code without having it...


  • Lifetime Qt Champion

    @Giakara said in PROBLEM TO SIGNALS AND SLOTS:

    fast::SurfaceExtraction::pointer mSurfaceExtraction = fast::SurfaceExtraction::New();

    Basic++ - it does not initialize the variable you want to.


Log in to reply