问题
Possible Duplicate:
Concatenating two QStrings with an integer
i'm looking forward to create a a string from 3 ints and one c++ stl string in QT, how can i do this? anyone know?, can't find something thats explain this procces?
this is my code were i create the elements in a lsit, but i want to print all elements and theyr properties not only name:
void Window::listMovies(){
ui->listMovies->clear();
vector <Movie> all = ctrl->getAllMovies();
for(int i=0; i <(int) all.size();i++){
QListWidgetItem*item = new QListWidgetItem(
QString::fromStdString(all[i].getName()),ui->listMovies);
item->setData(Qt::UserRole,QVariant::fromValue(all[i].getID()));
Movie objects have 1 string and 3 ints varaibles.
回答1:
QString str = QString::fromStdString( stl_string ) + " " +
QString::number( num1 ) + " " +
QString::number( num2 ) + " " +
QString::number( num1 );
There are a few different ways doing this.
回答2:
Use the arg()
functionality of QString
. Here is a real world example:
QString title("<b>Select Region of Interest:</b> %1.%2 - %3.%4 (%5x%6)");
title = title.arg(roi.x()).arg(roi.y()).arg(roi.right()).arg(roi.bottom())
.arg(roi.width()).arg(roi.height());
I assume you get the idea. Find it here in the Qt 4.8 documentation.
来源:https://stackoverflow.com/questions/11223674/concatenate-stl-stringintintint-in-qstring