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



  • 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?



  • Hi
    something like this?

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


  • This post is deleted!


  • @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.



  • 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?



  • @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>



  • 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!



  • @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 :)



  • you are most welcome :)



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