PDA

View Full Version : system volume in qslider controller



breakthecode
11th December 2011, 09:57
i want to control system volume by using qslider i write some code but some problem with build





void dcsinter::volume()

{

ui->horizontalSlider->setMinimum(0);

ui->horizontalSlider->setMaximum(100);

ui->horizontalSlider->setSingleStep(5);

int pos = ui->horizontalSlider->sliderPosition();

qreal apos = pos/100;



Phonon::AudioOutput *audio = new Phonon::AudioOutput;



audio.setVolume(apos);

}



build issues are " request for member 'setvolume' in 'saudio' , which is of non-class type 'phonon::AudioOutput"
i can't understand what the issue here

thanks

ChrisW67
13th December 2011, 07:07
The error message you quote does not match the code you have posted: always cut and paste the actual code and error message otherwise you risk getting no, or the wrong, answer.

Anyway, at line 21 you are using "audio" as if it is an instance of Phonon::AudioOutput instead of a pointer to one. Basic C++ mistake. Try:


audio->setVolume(apos);


In what is likely to be a few more common mistakes... The volume is being set on the new, heap allocated instance of Phonon::AudioOutput and the pointer variable then goes out of scope. You have no way to access this Phonon::AudioOutput later and have a memory leak as well.