enter image description here

int array[10]={3,5,7,2,5,9,9,5,4,1}; QString array_text=""; for (int i=0;i<10;i++) { array_text.append((QString)array[i]); } QLabel *array_label=new QLabel(this); QPushButton *sort_array_button=new QPushButton(this); sort_array_button->setText("Sort Array"); array_label->setText(array_text); setGeometry(200,200,300,300); array_label->move(100,100); sort_array_button->move(100,150); setWindowTitle("Sorting Array"); 

When you start the program on the label instead of numbers some strange characters are shown. Where am I wrong?

    1 answer 1

    Use QString::number() , in other words

     array_text.append(QString::number(array[i])); 
    • As a recommendation: in order to avoid such problems, refuse to use type C conversions. Instead, use the С ++ operators: static_cast, dynamic_cast, const_cast. Note that this code: array_text.append(static_cast<QString&>(array[i])); would cause errors at compile time. - aleks.andr