PDA

View Full Version : display in text browser



mecrazycoder
12th December 2010, 18:49
I am noob in QT as well as C++. Rite now I am trying to display value of iter->second but its not working. Here is the small piece of code

multimap<string, string>::iterator iter;

iter = findFile.find(fileToFind);

if ( iter != findFile.end() )
{
do
{
string temp = iter->second;
QString str;
str.fromStdString(temp);
ui->textBrowser->setText(str);;
cout << iter->first << " [DIR] " << iter->second << endl;
iter++;
}while (iter != findFile.upper_bound ( fileToFind ) );
}
Please help me out

tbscope
12th December 2010, 18:53
You need to convert it from a number to a string.
Check out the QString documentation, specifically something like QString::number or the QString arg(...) function.

mecrazycoder
12th December 2010, 19:01
Thanks for ur response. But I cant able to figure out the problem. So if possible can you please edit my code

squidge
12th December 2010, 19:22
'fromStdString' is static method, so you use it like so:



QString qstr = QString::fromStdString(str);

mecrazycoder
12th December 2010, 19:35
'fromStdString' is static method, so you use it like so:



QString qstr = QString::fromStdString(str);

Great it worked. Now i want to display results in text browser. But the problem I am facing is text browser display only the last result so can you please tell me how to populate all results(each result per line) in populate. How to integrate text browser with scroll bar. Tanx in advance

tbscope
12th December 2010, 20:45
Sorry, I thought second was a number (seconds).

hackerNovitiate
13th December 2010, 01:46
But the problem I am facing is text browser display only the last result so can you please tell me how to populate all results(each result per line) in populate. How to integrate text browser with scroll bar. Tanx in advance

The documentation for QTextBrowser is at http://doc.trolltech.com/4.7/qtextbrowser.html, and you can find all its methods here. Also, since QTextBrowser inherits QTextEdit, you can also use the methods in http://doc.trolltech.com/4.7/qtextedit.html.

Anyway, setText() removes old text before adding new ones. To add text without removing the old ones, use append().

If I'm not mistaken, the QTextBrowser should automatically have a scroll bar.

mecrazycoder
13th December 2010, 16:49
Thank you all for wonderful guidance