[SOLVED]Displaying an QList<QString>::Iterator inside of a QTextBrowser
-
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.
-
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 ?
-
@SGaist Yes, I want to show the Matching element and then the next 24 elements in the list :)
-
Then you can use the indexOf method to find the position of your text and from there iterate through the rest
-
@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 :)
-
Do you mean add everything at once and not line by line ?
-
@SGaist I need them to display line by line but they all have to be displayed at the same time like this.
-
Name
-
Email Address
-
user name
4 Password
- 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! -
-
You can build a QStringList then use join to create the output
-
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! :)
-
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
-
@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 :)
-
You're welcome !
Don't worry about time ;)
Happy coding !