Hello. I have an application in which when changing the position of the QSLider slider from the outside (keyboard, mouse), the slot for rewinding the track should be called. The problem is that when you click on the slider line, the slider moves, but the signal does not respond, but when I click purely on the slider, the signal is triggered.

connect(sldPlaybackProgress, &QSlider::sliderMoved, mediaplayer, &MediaplayerCfg::slot_setPosition ); // Работает // connect(sldPlaybackProgress, &QSlider::sliderReleased, this, &MainWindow::slot_onSliderClicked); // Не работает connect(this, &MainWindow::onSliderClicked /* сигнал исходит из slot_onSliderClicked()*/, mediaplayer, &MediaplayerCfg::slot_setPosition ); connect(sldPlaybackProgress, &QSlider::sliderReleased, this, &MainWindow::slot_onSliderClicked ); // Не работает 

Tried to use the sliderPressed() signal, but the result is the same.

    1 answer 1

    Quote from QSlider documentation (Qt 5.10)

    Signal valueChanged() - Emitted when the slider's value has changed. The tracking () determines whether this signal is emitted during user interaction.

    Try to subscribe to this signal, and read about tracking()

    UPD. Sample subscription to signal valueChanged()

    Headline

     #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDebug> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: void onValueChanged(int v){ qDebug() << v; } private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H 

    Implementation.

     #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->m_slider, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); } MainWindow::~MainWindow() { delete ui; } 

    Add a horizontal slider to the form, review it with m_slider , run this example and poke not along the slider but along the line (my signal arrives when the slider is moved by the slider, and when you click on the slider line).

    • The problem is that I need to rewind the track only with user intervention (because during playback of the track the slider will move to the right depending on the seconds played). If tracking is enabled, the slider emits the signal while the slider is being dragged. If the tracker is the slider. The problem is that the reaction occurs only when scrolling with a slider, i.e. if you click on the line, the slider will move, but it will not change the value - Recursive Daun
    • @RecursiveDaun added an example. Subscribe to the valueChanged() signal all the same and make sure that it does not suit you. - vegorov