Unsolved hot to change int to the string type
-
Hi, i'm using qt5.5 on my computer.
I have a program like below.void MainWindow::on_horizontalSlider_volume_valueChanged(int value) { QString info; Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info); qDebug()<<info; }
But it will show the error for me when i compile, it's the content of the error.
mainwindow.cpp:2697:105: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+' Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info);
How can i fix the problem?
I don't know where did i do wrong?
Please help! -
@victor-wang To convert an Interger into a String is kind of the part basics of the c++/qt libary. Did you look herebefore posting?
Anyway, you can either use arg
or the static QString::Number -
@J-Hilk is correct but in this specific case I would not use
arg()
because it localises the string (i.e. it might put in thousands separators and use local decimal separators) -
try:
QStringList() << "-c" << "/usr/bin/amixer set Speaker " + QString::number(value) + "%"