[SOLVED]QFile and QTextStream Question
-
[quote]
@ int h_slide1 = ui->hueSlide1->value();
QFile valueHSV("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Text)){
qDebug() << "File not able to open" << endl;
return;
}
QTextStream hsv(&valueHSV);
hsv << h_slide1;
qDebug() << "Value ="<<h_slide1
valueHSV.close();
@
[/quote]
in order to get slider value you should write above code inside on_horizontalSlider_valueChanged() slot. -
Hii.
void QAbstractSlider::valueChanged ( int value ) [signal]
This signal is emitted when the slider value has changed, with the new slider value as argument.
http://qt-project.org/doc/qt-4.8/qabstractslider.html#valueChanged
This is the signal you need to connect with your slot .just like when you connect your QPushButton's clicked signal to it's Slot_clicked();
hope you know signal and slot
. -
because i am now writing this in a function
:
@void Dialog::getValue()
{
int h_slide1 = ui->hueSlide1->value();
QFile valueHSV("/home/pi/valueHSV/hsv.txt");
if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Text)){
qDebug() << "File not able to open" << endl;
return;
}
QTextStream hsv(&valueHSV);
hsv << h_slide1;
qDebug() << "Value ="<<h_slide1
valueHSV.close();
}@ -
hi
you can take a reference from the following link
http://www.codeprogress.com/cpp/libraries/qt/qProgressbarSetValueExample.php#.U7J--ZSSwb8[Edited: Remember it is an old example using 4.7]
-
[quote author="YDYD" date="1404207347"]ermm.. this link not working..[/quote]
link is perfectly working.[quote author="YDYD" date="1404207723"]The example i can understand, but whn the slider move, can i save the current value to a txt file?[/quote]
yes that is why this signal is given.
[quote author="YDYD" date="1404207829"]Hi Lam,
I dont think your suggestion could work, i could not call ui into the function.[/quote]
the example does not use Qt designer Widget it is taking on run time.
I think the problem is you have to understand the basics first like
@
creating .h and .cpp file inheriting QWidget/QMainWindow or Qdialog.
SIGNAL and SLOT
and many more thing.
@