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. [SOLVED]Displaying an QList<QString>::Iterator inside of a QTextBrowser
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Displaying an QList<QString>::Iterator inside of a QTextBrowser

Scheduled Pinned Locked Moved General and Desktop
will not displaqlistqstringiteqtextbrowser di
12 Posts 2 Posters 4.5k Views 2 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.
  • S Offline
    S Offline
    Suroh6
    wrote on 28 Apr 2015, 16:29 last edited by Suroh6 5 Feb 2015, 10:47
    #1

    I'd asked a question about this a while back and got an answer that sorted of helped but only partially, so I'd like to try this again.

    My issue is that I'm attempting to iterate through a QList<QString> While searching for a specific user entered " phrase " via a lineEdit.

        void Passguard::on_lineEdit_3_returnPressed() // This is where the user stores  some thing in the list
       {
            QString DefaultText = "Username: ";
               QString NewLine = "\n";
                   QString UserName = "User name: ";
                      QString Usr = ui->lineEdit_3->text();
                         QFile file;
                            file.setFileName("C:\\Passguard\\Passguard.txt");
                                file.open(QIODevice::Append);
                                     ui->lineEdit_3->text();
                                    
                 QTextStream OutStream(&file);
                       MyListings.push_back(UserName);
                             MyListings.push_back(Usr);
                                  MyListings.push_back(NewLine);
                                       MyListings.push_back(NewLine);                                        
                                           OutStream << Encrypt(UserName) << Encrypt(Usr);
                                               OutStream << Encrypt(NewLine) << Encrypt(NewLine);
                                                  ui->lineEdit_3->clear();
                                                        ui->lineEdit_3->setPlaceholderText(DefaultText);
                                                             file.close();
         }
    
    
    
    
    
    
    
    
    
    
    
             void Passguard::on_pushButton_7_clicked() // This is where the user searches the list for         some thing specific
               {
                QList<QString>::iterator S;
                     QString UserChoice = ui->lineEdit->text();
    
              if((S = qfind(MyListings.begin(), MyListings.end(),UserChoice)) != MyListings.end())
                {
                        for(int Index = 0; Index < 24; ++Index)
                             {
                                    ui->textBrowser->setText(*S);
                                        ++Index;
                            }
                }
    

    Needless to say, I'm attempting to search the list to find some thing that user stored with in it, based off of what they input into the QlineEdit.

    So naturally if what they input does not exist it wont show up in the QtextBrowser, if it does exist it will show up.

    The problem is I want not only the string that they searched for to show up but also the next 24 elements in the list as well and I need them all to display inside of the QtextBrowser at the same time.

    Currently I'm only being able to display things one at a time.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Apr 2015, 23:49 last edited by
      #2

      Hi,

      If i understand you correctly, you want to show the first element matching your query and the 24 following elements on the list ? Or should it be up to 24 elements matching your query ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 29 Apr 2015, 00:06
      0
      • S SGaist
        28 Apr 2015, 23:49

        Hi,

        If i understand you correctly, you want to show the first element matching your query and the 24 following elements on the list ? Or should it be up to 24 elements matching your query ?

        S Offline
        S Offline
        Suroh6
        wrote on 29 Apr 2015, 00:06 last edited by Suroh6
        #3

        @SGaist Yes, I want to show the Matching element and then the next 24 elements in the list :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Apr 2015, 22:35 last edited by
          #4

          Then you can use the indexOf method to find the position of your text and from there iterate through the rest

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 29 Apr 2015, 23:24
          0
          • S SGaist
            29 Apr 2015, 22:35

            Then you can use the indexOf method to find the position of your text and from there iterate through the rest

            S Offline
            S Offline
            Suroh6
            wrote on 29 Apr 2015, 23:24 last edited by Suroh6
            #5

            @SGaist I understand that. I can locate the elements I need to find, I can also display each one individually inside the text browser with out any issues.

            My problem is that I'm not able to display every thing inside of the QtextBrowser at the same time like the following

            Matched Element

            Next Element after matched string

            Next Element

            Next Element

            Next Element

            Next Element

            I'm not understanding some thing, and I'm sure it's a small over sight thank you for the help you've given me so far I really do appreciate it :)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 30 Apr 2015, 22:37 last edited by
              #6

              Do you mean add everything at once and not line by line ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply 30 Apr 2015, 23:17
              0
              • S SGaist
                30 Apr 2015, 22:37

                Do you mean add everything at once and not line by line ?

                S Offline
                S Offline
                Suroh6
                wrote on 30 Apr 2015, 23:17 last edited by Suroh6 5 Jan 2015, 19:48
                #7

                @SGaist I need them to display line by line but they all have to be displayed at the same time like this.

                1. Name

                2. Email Address

                3. user name

                4 Password

                1. Description

                the user searches for a specific " Listing " by inputing a string that should match " Name " and if it exists, it will display Name and the other four above elements at the same time.

                So far I've only managed to get them to show up one at a time, doing this in straight c++ is simple which is why I'm not sure what I'm doing wrong. Consider the following code Snippet as an example of what I'm trying to do!

                  list<string> MyList;
                  MyList.push_back("Name");  
                  MyList.push_back("Email Address");
                  MyList.push_back("Username"); 
                  MyList.push_back("Password"); 
                  MyList.push_back("Description");    
                         string UserInput;
                        std::list<std::string>::iterator iter;
                
                std::cout << " Please enter some thing to search for " << std::endl; 
                    getline(cin, UserInput);
                     if((iter = std::find(MyList.begin(), MyList.end()  , UserInput )) != MyList.end())
                        {
                            for(int index = 0; index < 5; ++index)
                                 {
                                      std::cout << *iter << " ";
                                      ++iter;
                                 }
                             std::cout << std::endl;
                        }  //This code snippet would print out  " Name  Email Address Username Password Description " 
                

                This is what I'm trying to do, I can deal with out it being line by line I just can't figure out how to output what I need in the
                QtextBrowser Like the above example!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 1 May 2015, 23:00 last edited by
                  #8

                  You can build a QStringList then use join to create the output

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply 2 May 2015, 01:00
                  0
                  • S SGaist
                    1 May 2015, 23:00

                    You can build a QStringList then use join to create the output

                    S Offline
                    S Offline
                    Suroh6
                    wrote on 2 May 2015, 01:00 last edited by
                    #9

                    @SGaist

                    Unfortunately it's still not what I'm looking for ( I could be wrong lol, I'm finding some things are harder to get used to with Qt)

                    I could be wrong, but join() would basically be the same as prepend right? If so That's not the problem .

                    ui->textBrowser.setText(" My problem is here, the display its self");

                    I've used Qts Console output to run various different tests with " Straight C++ " and I get my desired output, I also get it if I use the various qt functions etc.. I just can't get it to display properly in the text browser I may have to switch to some thing else for my display.

                    Any way thanks for trying I'm going to mark this as solved and I'll just continue to scour the documentation, I'll get it eventually and when I do I'll update this just in-case some one needs to solve the same problem! :)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 2 May 2015, 21:08 last edited by
                      #10

                      In this case you are wrong, join create one string from your list using the given separator e.g. \n

                      If that doesn't fit your need, then just generate the complete string that you want to display and only then add it to the QTextBrowser

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply 3 May 2015, 20:28
                      1
                      • S SGaist
                        2 May 2015, 21:08

                        In this case you are wrong, join create one string from your list using the given separator e.g. \n

                        If that doesn't fit your need, then just generate the complete string that you want to display and only then add it to the QTextBrowser

                        S Offline
                        S Offline
                        Suroh6
                        wrote on 3 May 2015, 20:28 last edited by
                        #11

                        @SGaist At first I wasn't exactly clear on what you meant, but I see now and I agree that did solve my problem! Thank you for all the help and sorry it took so long :)

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 3 May 2015, 21:05 last edited by
                          #12

                          You're welcome !

                          Don't worry about time ;)

                          Happy coding !

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          1/12

                          28 Apr 2015, 16:29

                          • Login

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