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. Error with QList
Qt 6.11 is out! See what's new in the release blog

Error with QList

Scheduled Pinned Locked Moved General and Desktop
37 Posts 5 Posters 30.6k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gogoi
    wrote on last edited by
    #22

    ya i have not created two instance of QList<login>..
    please check out this

    @void MainWindow::saveSettings()
    {

     QSettings settings;
     settings.beginWriteArray("logins");
     for (int i = 0; i < logins.size(); ++i) {
         settings.setArrayIndex(i);
         settings.setValue("userName", list.at(i).userName);
         Login login;  
        ui->lineEdit->settext(login.userName);
    
         settings.setValue("password", list.at(i).password);
          ui->lineEdit_2->settext(login.password);
     }
     settings.endArray();
    

    }
    @

    regards
    gogoi

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #23

      In your 10 and 13 lines, both line edits will have blank text. Use list.at(i) instead of local login variable.
      If your list is member of MainWindow class, or if it's global in MainWindow.cpp, your code should be ok, if you remove line 9.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gogoi
        wrote on last edited by
        #24

        hey thanks for the info..i did that,,but no effect ,my .ini file shows only this output..

        [logins]
        size=0

        regards
        gogoi

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #25

          If you have @QList<Login> m_logins@ member in your MainWindow class, and if in read function you'll use m_logins.append, I'm sure that write function will write in ini file as many Login as you appended before.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gogoi
            wrote on last edited by
            #26

            No cincirin..I coded the 2 functions according to your suggestions..but its not entering the loop in the savesettings function..and everytime it says size=0;//
            so i think on click of a button we shouls set the username and passwd..
            this way..
            @void MainWindow::on_set_clicked()
            {

            login.userName=ui->lineEdit->text();
            login.password=ui->lineEdit_2->text();
            logins.append(login);
            

            }@

            i dont know whether i m right or wrong..u please just check out//

            regards
            gogoi

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #27

              Ok, in the following code if you call Test::count function, you'll see as many Login as you appended:
              @
              class Test
              {
              public:
              void append();
              int count()const;

              protected:
              struct Login
              {
              QString userName;
              QString password;
              };

              QList<Login> m_loginsList;
              

              };

              void Test::append()
              {
              Login log = {"user", "pwd"};
              m_loginsList.append(log);
              }

              int Test::count()const
              {
              return m_loginsList.size();
              }

              int main(int argc, char *argv[])
              {
              Test t;
              t.append(); // one item
              t.append(); // two items
              // ...
              qDebug("%d", t.count()); // print how many items are in list
              return 0;
              }
              @

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gogoi
                wrote on last edited by
                #28

                ok.thanks..so whether my code is correct..?

                hey now my ini file is showing..the data which i input through the lineedit..but the username and password are not appending in the list..I mean the next time when i run and enter usrname and passwd..the previous username and password will be lost..

                regards
                gogoi

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cincirin
                  wrote on last edited by
                  #29

                  In the next time when you run the application, first read settings from ini, and append in logins list

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gogoi
                    wrote on last edited by
                    #30

                    from where shall i call it?
                    readsettiing(); or writesettings(); and how?

                    regards
                    gogoi

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gogoi
                      wrote on last edited by
                      #31

                      these are my working functions..now please help me out..how shall i first read settings from ini and append in logins list..

                      @void MainWindow::readSettings()
                      {

                       QSettings settings;
                       int size = settings.beginReadArray("logins");
                      
                      
                       for (int i = 0; i <size; ++i)
                       {
                           settings.setArrayIndex(i);
                      
                           login.userName = settings.value("userName").toString();
                           ui->lineEdit->setText(login.userName);
                           login.password = settings.value("password").toString();
                           ui->lineEdit_2->setText(login.password);
                           logins.append(login);
                       }
                       settings.endArray();
                      

                      }

                      void MainWindow::saveSettings()
                      {
                      QSettings settings;

                       login.userName=ui->lineEdit->text();
                       login.password=ui->lineEdit_2->text();
                      
                       logins.append(login);
                      
                       settings.beginWriteArray("logins");
                      
                       for (int i = 0; i < logins.size(); ++i) {
                           settings.setArrayIndex(i);
                           settings.setValue("userName", logins.at(i).userName);
                           settings.setValue("password", logins.at(i).password);
                      
                       }
                       settings.endArray();
                      

                      }
                      @

                      regards
                      gogoi

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        gogoi
                        wrote on last edited by
                        #32

                        hey i got it..

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gogoi
                          wrote on last edited by
                          #33

                          Hi cicncirin r u there,
                          Hey Whether we can get the date in an .ini file?

                          regards
                          gogoi

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            cincirin
                            wrote on last edited by
                            #34

                            Yes, sure. You can write an "variant":http://doc.qt.nokia.com/latest/qvariant.html#QVariant-23
                            Then, you can read variant from ini and transform to "date time":http://doc.qt.nokia.com/latest/qvariant.html#toDateTime

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              gogoi
                              wrote on last edited by
                              #35

                              ok thanks cincirin...hey one morething i like to ask u..Actually i want to open a virtual keyboard on click of a pushbutton..so how shall i do it...

                              regards
                              gogoi

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                cincirin
                                wrote on last edited by
                                #36

                                "VirtualKeyboard":http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  goetz
                                  wrote on last edited by
                                  #37

                                  [quote author="gogoi" date="1306838572"]ok thanks cincirin...hey one morething i like to ask u..Actually i want to open a virtual keyboard on click of a pushbutton..so how shall i do it...
                                  regards
                                  gogoi[/quote]

                                  You've opened a "separate thread":http://developer.qt.nokia.com/forums/viewthread/6371/ for this, so I'm closing this one.

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply
                                  0

                                  • Login

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