Serial Port Problem

Hello, I have an arduino mega 2560 and i want to set the value of brightness of a led using an application written with Qt which communicates with the arduino through the serial port (USB). The problem is that: the value of the serial port is always 255. When i try to change the value with the Qt widget, it changes... but the next loop it returns to 255.

Can you tell me why i have this problem? The sketch is that

const int ledPin = A15; // the pin that the LED is attached to
byte brightness;
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {

  // read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
Serial.println(brightness);
// set the brightness of the LED:
analogWrite(ledPin, brightness);

}

Thanks

void loop() {
    // read the most recent byte (which will be from 0 to 255):
   if (Serial.available() > 0) {
        brightness = Serial.read();
        Serial.println(brightness);
        // set the brightness of the LED:
        analogWrite(ledPin, brightness);
    }
}

It works!

Thank You