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. File Browser - problem with QListWidget
Forum Updated to NodeBB v4.3 + New Features

File Browser - problem with QListWidget

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.6k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Eubie
    wrote on last edited by
    #1

    Dear all,

    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,
    Daniel

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Have you verified that Item is being populated correctly (with a QDebug or a breakpoint?)

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Eubie
        wrote on last edited by
        #3

        mlong, thank you. Yes, a QString of expected content is created, something like "20120809 235959 728;1"...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          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.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Eubie
            wrote on last edited by
            #5

            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().

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              Double click on your ListWidget and you should get an Edit List Widget dialog. (Either that or right click -> Edit Items.)

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                Eubie
                wrote on last edited by
                #7

                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();
                listWidget->setSortingEnabled(false);
                @

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  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.

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Eubie
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      Eubie
                      wrote on last edited by
                      #10

                      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();
                      ...
                      ui.listWidget->scrollToItem(ToSelect);
                      @

                      Many thanks for your patience.
                      Daniel

                      1 Reply Last reply
                      0

                      • Login

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