QList<QStringList> elemen t not getting replaced!



  • In my Qt c++ application I have a QList<QStringList> named "names". It has size of 10(has 10 QStringLists). But when I try to insert a new QStringList to an existing position and try to print the values the old QStringList remains in that postion!How can I correct this?
    The code is as follows:
    void NewOrders::createNewName(){
    QString firstName="John";
    QString lastName="Smith";

    QStringList newName;
    newName<<firstName<<lastName;
    names[2]<<newName;
    }

    void MainWindow::on_pushButton_clicked(){
    QString concatName="";
    for(int i<0;i<names[2].size();i++){
    concatName+=names[2][i];
    }
    ui->label->setText(concatname);
    }

    but when I print the contents of names[2] by pressing the button still the old name appears not John Smith! How can I correct this?



  • @Kushan
    Hi, try it with this one, replace

    names[2]<<newName;

    with

    names.replace(2,newName);



  • @J.Hilk Thanx alot


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.