PDA

View Full Version : [HELP] how to get a value of slider from ui_XXXX.h



YDYD
30th June 2014, 09:07
Hi all,

newly register, new to Qt here.

Here is a new question:

I am recently designing a GUI using dialog.ui
i used a lot of slider, i need to read the slider value,
anyone tell me how can i get it from ui_dialog.h ?
is it possible?
here is a photo of GUI:
10484

After this question, i would like to save these values that i get from slider in to a text file that using XML format.
How can i achieve this?

Please advise,

Best regards,
YDYD

anda_skoa
30th June 2014, 10:34
If you have chosen a designer form class template in QtCreator then you should have a dialog.h and a dialog.cpp generated with the .ui file.

The dialog.cpp will have an include for the generated header and have created an instance of the class and stored that in the "ui" pointer.

The code to access any widget present in the designer form is then


ui->nameOfTheWidget


e.g. for a slider named "slider1", getting the value would be


int value = ui->slider1->value();


Cheers,
_

YDYD
30th June 2014, 10:57
Hi anda_skoa,

appreciate this!

this help me a lot!

Added after 8 minutes:

Hi,
can i printf in LXterminal for checking value of
int value ?

and one more question:

Could i save the value i get into a .TXT file?

anda_skoa
30th June 2014, 15:50
can i printf in LXterminal for checking value of
int value ?



qDebug() << value;



and one more question:

Could i save the value i get into a .TXT file?

See QFile and QTextStream.

Cheers,
_

YDYD
1st July 2014, 08:20
Hi,

i did try this the whole day, i just could sote the value in a txt file... i did as following :

int h_slide1 = ui->hueSlide1->value();
QFile valueHSV("/home/pi/valueHSV/hsv.txt")
if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Append))
return;
QTextStream hsv(&valueHSV);
hsv << h_slide1;