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]How do I display the contents of a QStringList in a QTextBrowser

[SOLVED]How do I display the contents of a QStringList in a QTextBrowser

Scheduled Pinned Locked Moved General and Desktop
qstringlist disqstringlistiterdisplay qstring
9 Posts 2 Posters 26.1k 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.
  • S Offline
    S Offline
    Suroh6
    wrote on last edited by Suroh6
    #1

    Okay so I'm trying to display the contents of my QStringList inside of a QtextBrowser, or rather to be more accurate...

    I'm trying to allow the user to enter a specific word(s), iterate through the QStringList and display the results inside of the QTextBrowser if any valid ones are found.

    I'm doing this by using a push button and a lineEdit, the user would type the information into the lineEdit, then click the button and the contents would be displayed in the textBrowser.

      void Passguard::on_pushButton_7_clicked() // Search Specific Listing
            {  
                      ui->lineEdit->text();
                         for (QStringList::Iterator S = MyListings.begin(); S != MyListings.end(); ++S)
                     {
                              ui->textBrowser->setText(*S);   /* The variable QStringList MyListings is global */
                     }
           } 
    

    I don't get any errors, it just wont display inside of the textBrowser my thoughts are the following.

    1. ui->textBrowser->setText(*S); wont accept *S but I figured I'd get some sort of error warning if that was the case,

    if I used straight c++ I could do the following (I'm only using the below code as an example)

            for (list<string>::iterator Itt = MyListings.begin(); Itt != MyListings.end(); Itt++) 
                  { 
                        cout << " " << *Itt;  /* and it would display the contents in a terminal if any were found. */
                  } 
    
    1. Maybe I have to convert it to a QString after the iteration and display it like that?

    2. Or perhaps It's not even registering the input from the line edit?

    Does any one have some suggestions as to how I can do this?

    1 Reply Last reply
    0
    • HamedH Offline
      HamedH Offline
      Hamed
      wrote on last edited by
      #2

      Hi
      something like this?

          QStringList s;
          s << "your" << "string" << "list";
          for(int i=0 ; i < s.length() ; i++)
          ui->textBrowser->append(s.at(i));
      

      HamedBabaeyan@yahoo.com
      for more interesting stuff

      S 1 Reply Last reply
      0
      • HamedH Hamed

        Hi
        something like this?

            QStringList s;
            s << "your" << "string" << "list";
            for(int i=0 ; i < s.length() ; i++)
            ui->textBrowser->append(s.at(i));
        
        S Offline
        S Offline
        Suroh6
        wrote on last edited by Suroh6
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Suroh6
          wrote on last edited by
          #4

          @Hamed unfortunately not, it would have to be some thing comparable to the following, My Variable QStringList MyListing contains many strings all of which come form user input.

           ui->lineEdit->text();
            for (QStringList::Iterator S =  MyListings.begin(); S != MyListings.end(); S++)
                  {
                       ui->textBrowser->setText(*S);
                  } 
          

          My goal is to take the user input string from the line edit, then iterate through QStringList MyListings; to find any matching words
          then to display those words inside of the QTextBrowser. Perhaps your method works as well I tried it but it didn't have any effect I'm still not able to display the found string in the text browser.

          Sorry about the multiple posts for some reason my initial reply was deleted, as was the edited version O_0.

          1 Reply Last reply
          0
          • HamedH Offline
            HamedH Offline
            Hamed
            wrote on last edited by
            #5

            I don't know if I'm get you right, do you mean that you want to write some kind of search tool?
            you have a string list and want to find the string that the user Imports. right?

            HamedBabaeyan@yahoo.com
            for more interesting stuff

            S 1 Reply Last reply
            0
            • HamedH Hamed

              I don't know if I'm get you right, do you mean that you want to write some kind of search tool?
              you have a string list and want to find the string that the user Imports. right?

              S Offline
              S Offline
              Suroh6
              wrote on last edited by
              #6

              @Hamed yes. I tried your code before but it didn't work I may have messed it up some how I'm still learning to work with qt.

              I'm trying to use QStringList::Iterator S; as the searching tool.

              I want to start the iteration at the beginning of the file and end at the end of the file.

              I'm attempting to search the lists existing variables via a user input string from a QlineEdit

              So if the string that the user inputs into the lineEdit doesn't match any of the strings in the QStringList it wont display any thing.

              But if it does match some thing that exists with in the QStringList I want it to display the matching string in the QtextBrowser.

              Perhaps I'm using The QStringList wrong?

              I'm looking for the equivalent of the ( stl )
              list < string>

              1 Reply Last reply
              0
              • HamedH Offline
                HamedH Offline
                Hamed
                wrote on last edited by Hamed
                #7

                this should work for you :

                QStringList s;
                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                    s << "your" << "string" << "list";
                }
                void MainWindow::on_pushButton_clicked()
                {
                    for(int i=0 ; i < s.length() ; i++)
                    {
                        if(ui->lineEdit->text() == s.at(i))
                        ui->textBrowser->setText(s.at(i));
                    }
                }
                

                EDIT : I used a global variable in the code for the sake of simplicity but never use them! they are devil!

                HamedBabaeyan@yahoo.com
                for more interesting stuff

                S 1 Reply Last reply
                0
                • HamedH Hamed

                  this should work for you :

                  QStringList s;
                  MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                      s << "your" << "string" << "list";
                  }
                  void MainWindow::on_pushButton_clicked()
                  {
                      for(int i=0 ; i < s.length() ; i++)
                      {
                          if(ui->lineEdit->text() == s.at(i))
                          ui->textBrowser->setText(s.at(i));
                      }
                  }
                  

                  EDIT : I used a global variable in the code for the sake of simplicity but never use them! they are devil!

                  S Offline
                  S Offline
                  Suroh6
                  wrote on last edited by
                  #8

                  @Hamed Ah okay awesome thank you :) I see where I messed up it was my placement of if(ui->lineEdit->text() == s.at(i)) for some reason I had it reversed, can't believe I did that haha.

                  Thank you again :)

                  1 Reply Last reply
                  0
                  • HamedH Offline
                    HamedH Offline
                    Hamed
                    wrote on last edited by
                    #9

                    you are most welcome :)

                    HamedBabaeyan@yahoo.com
                    for more interesting stuff

                    1 Reply Last reply
                    1

                    • Login

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