Concatenate stl string+int+int+int in QString [duplicate]

走远了吗. 提交于 2020-01-03 05:17:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!