tags:

views:

26

answers:

1

hello everybody, I need small help, I'm using class Qslider from qt, how can I get the number of the current position of the cursor (with which function I can do that) thanks in advance

edited

I want to implement one thing: when I reach the max of the interval I want to quit, how can I do this with slot and signal?

+2  A: 

I am assuming you want the value of the slider?

int QSlider::value ()

I looked at the code in your other post and this is what I came up with after cleaning it up:

main.cpp

#include <QApplication>
#include "mywidget.h"

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 MyWidget widget;
 widget.show();
 return app.exec();
}

mywidget.h

 #ifndef MYWIDGET_H
 #define MYWIDGET_H
 #include <QWidget>
 #include <QObject>
 include <QPushButton>
 #include <QSlider>

 class MyWidget : public QWidget
 {
  Q_OBJECT
  public:
MyWidget(QWidget *parent = 0);
~MyWidget(){};
  public slots:
void getSliderValueAndQuit();
  private:
 QPushButton *quit;
 QSlider *slider;
 };

 #endif // MYWIDGET_H

myWidget.cpp

 #include "mywidget.h"
 #include <QWidget>
 #include <QObject>
 #include <QApplication>
 #include <QFont>
 #include <QLCDNumber>
 #include <QPushButton>
 #include <QSlider>
 #include <QVBoxLayout>

 MyWidget::MyWidget(QWidget *parent) :
 QWidget(parent)
 {
quit = new QPushButton(tr("Quit"));
quit->setFont(QFont("Times", 18, QFont::Bold));

QLCDNumber *lcd = new QLCDNumber(3);
lcd->setSegmentStyle(QLCDNumber::Flat);

slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 999);
slider->setValue(0);

connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));

connect(slider, SIGNAL(valueChanged(int)),lcd, SLOT(display(int)));
connect(slider,SIGNAL(sliderReleased()), SLOT(getSliderValueAndQuit()));

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(quit);
layout->addWidget(lcd);
layout->addWidget(slider);
setLayout(layout);
 }

 void MyWidget::getSliderValueAndQuit(){
if(slider->value() == slider->maximum())
    close();
 }
Kms254