0

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.

Community
  • 1
  • 1
Bogdan M.
  • 2,161
  • 6
  • 31
  • 53

2 Answers2

5
QString str = QString::fromStdString( stl_string ) + " " +
              QString::number( num1 ) + " " +
              QString::number( num2 ) + " " +
              QString::number( num1 );

There are a few different ways doing this.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
4

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.

ypnos
  • 50,202
  • 14
  • 95
  • 141