Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QList<QStringList> elemen t not getting replaced!
QtWS25 Last Chance

QList<QStringList> elemen t not getting replaced!

Scheduled Pinned Locked Moved Solved General and Desktop
qstringlistvaluechange
3 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kushan
    wrote on 19 Oct 2017, 12:25 last edited by
    #1

    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?

    J 1 Reply Last reply 19 Oct 2017, 12:33
    0
    • K Kushan
      19 Oct 2017, 12:25

      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?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 19 Oct 2017, 12:33 last edited by
      #2

      @Kushan
      Hi, try it with this one, replace

      names[2]<<newName;

      with

      names.replace(2,newName);


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      K 1 Reply Last reply 19 Oct 2017, 12:45
      4
      • J J.Hilk
        19 Oct 2017, 12:33

        @Kushan
        Hi, try it with this one, replace

        names[2]<<newName;

        with

        names.replace(2,newName);

        K Offline
        K Offline
        Kushan
        wrote on 19 Oct 2017, 12:45 last edited by
        #3

        @J.Hilk Thanx alot

        1 Reply Last reply
        1

        3/3

        19 Oct 2017, 12:45

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved