File Browser - problem with QListWidget
I am trying to write a browser for large txt files, where each line contains "date time price deal_size". The files are large (2GB+) hence most editors crash (incl. Notepad++).
The main focus of the application is "I want a chunk of this file that is around a given date/time". Hence, I go through the file and want to load into memory some surrounding of this particular line., then I want to show this data from memory. I chose QListWidget for storing the resulting lines, however, I can"t make Qt display my data. My code is
int iItemNo = 0;
QString Item = QString::fromStdString( Tick.Date.szExport( QTDateStringFormat::YYYYMMDD_NoSlash ) ) + " ";
Item += QString::fromStdString( Tick.Time.szExport( QTTimeStringFormat::HHMMSS_NoColons_NoDots) ) + " ";
Item += QString::fromStdString( Tick.fPrice.szExport(1) + " " );
Item += QString::number( (int)Tick.iContract_Count );
ui->listWidget->insertItem( iItemNo++, Item );@
After adding any number of Items, the Widget is still blank (visually). So the questions are two: is there a better widget for just showing lines of a textfile (the user mustnt have the possibility to modify lines, so no QTextEdit)? If not, what am I doing wrong with the QListWidget?
Any input is much appreciated,
Have you verified that Item is being populated correctly (with a QDebug or a breakpoint?)
mlong, thank you. Yes, a QString of expected content is created, something like "20120809 235959 728;1"...
If you set some default text in your widget in designer and disable trying to add your text, does that text still show up properly?
Edit to add:
Also, if you just want to append each string at the end of the list, you can use addItem() rather than insertItem(), so you don't have to worry about the position index.
I am new to Qt, tried googling "QListWidget default text", ran through the options in the Designer, but didnt find the way to do this. Neither did I find anything mentioning disabling addItem().
Double click on your ListWidget and you should get an Edit List Widget dialog. (Either that or right click -> Edit Items.)
Thank you. Yes, when I add an Item in the Designer, it appears in the widget after build without problems. What kind of light does this shed on my problem? The only lines of code I found to have anything to do with the object are
const bool __sortingEnabled = listWidget->isSortingEnabled();
bq. What kind of light does this shed on my problem?
Just making sure that your widget was being displayed properly.
There must be some other problem somewhere along the way. To me, the snippet of code you posted looks ok. It's hard to diagnose anything else without seeing more of your code.
mlong, thank you for bearing with me. It might be the case that I am doing sth wrong by using QtDesigned and VS 2010 both for code manipulation (QTDesigner has bettern Intellisense for Qt, but VS is faster and Im used to it). I will try writing the whole thing in VS exlusively and will see whether that helps. Many thanks. Daniel
OK, got it sorted out. Now everything works just fine. Im facing one last problem - with my QListWidget. I populate it with data and then I want to select and scroll to one specific item. Selecting works, however scrolling does not
QListWidgetItem * ToSelect;
ToSelect = ui.listWidget->currentItem();
Many thanks for your patience.