Results 1 to 9 of 9

Thread: Odd behavior when populating a Table

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Odd behavior when populating a Table

    Hi there, I guess this marks my first post here. I've been going at my own pace with Qt for a few weeks (and I have to say it's got to be my favorite Application development library of all time!)

    Anyway, since I'm a big music person, I have a good lot of files with different naming conventions and such, so I thought it would be cool to apply my skills as a programmer and write a simple batch music file renamer as my first independent Qt app. I have made some surprising progress in the first day, I have been able to specify a folder, and populate a table with the files in that folder (even being able to filter out to specific filetypes!) I know it must sound boring to you guys, but as a programmer who's spent most of his time with more realtime application development (games and such), I think it's just magical.

    I know my title states "Odd behavior," but in actual fact it's probably something so simple that I've overlooked and need a good bonk over the head for, but anyway, before I populate my table, all I have are three columns "File Name" (I'm still looking for a way to make this column non-editable), "Song Title" and "Song Number." The idea is that you're supposed load a folder (this is assuming you dont have all your mp3's in one folder, but rather separate them into separate folders by artist, album, whatever like myself), and then set some Global fields (artist name, album title, etc), then you can go into the local fields and set them yourself (or I could try to develop an algorithm to do it for you if I ever are smart to do that enough), then hit the rename button and its all done for you.

    Before I load in a folder, my application looks like this:



    And after I load in say Aerosmith's Ultimate Hits CD1:



    As you can see, the Column names have been replaced by numbers. Now I think the solution to this is probably very simple (problems like these usually are), but I cant for the life of me think of what is going on...

    Also the obligatory source code:

    Qt Code:
    1. void BatchRenamer::populateTable( QString folderName )
    2. {
    3. // no need to validate folderName because it's already done in openFolder()
    4. QDir activeDirectory( folderName );
    5. QStringList fileList = activeDirectory.entryList( QStringList() << "*.mp3" << "*.wma", QDir::Files );
    6.  
    7. // clear the current file list before doing anything
    8. ui.tblFiles->clear();
    9. if ( !oldFileList.isEmpty() )
    10. {
    11. for ( int i = 0 ; i < oldFileList.size() ; i++ )
    12. {
    13. ui.tblFiles->removeRow(i);
    14. ui.tblFiles->hideRow(i);
    15. }
    16. }
    17.  
    18.  
    19. for ( int i = 0; i < fileList.size() ; i++ )
    20. {
    21. QTableWidgetItem* item = new QTableWidgetItem( fileList.at(i));
    22. ui.tblFiles->insertRow(i);
    23. ui.tblFiles->setItem(i, 0, item);
    24. ui.tblFiles->showRow(i);
    25. }
    26.  
    27. oldFileList = fileList;
    28. }
    To copy to clipboard, switch view to plain text mode 

    And the method that calls populateTable(), which itself is called by a connection of the Find folder button clicked signal:
    Qt Code:
    1. void BatchRenamer::openFolder()
    2. {
    3. QString folderName = QFileDialog::getExistingDirectory( this, "Select Media Folder" );
    4.  
    5. if( !folderName.isEmpty() )
    6. {
    7. ui.ledSelectedFolder->setText(folderName);
    8. populateTable( folderName );
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your time. I would really appreciate instead of someone posting the code saying this works: go, take the time and explain to me why it's doing what it's doing and how I can go about fixing it. Of course, you dont have to though.

    tl;dr:
    When I populate my table, the column names get replaced with numbers.
    Last edited by Kyle_Katarn; 5th April 2011 at 18:26. Reason: spelling corrections

Similar Threads

  1. Querying a database and populating a combobox
    By Splatify in forum Newbie
    Replies: 7
    Last Post: 21st February 2011, 11:28
  2. Populating, signals and comboboxes
    By ShamusVW in forum Newbie
    Replies: 6
    Last Post: 12th August 2010, 06:43
  3. Replies: 3
    Last Post: 8th December 2009, 10:49
  4. Error when populating lazily QListView
    By Bakuriu in forum Qt Programming
    Replies: 2
    Last Post: 29th October 2009, 11:56
  5. QTableView populating question
    By onefootswill in forum Newbie
    Replies: 8
    Last Post: 7th August 2008, 22:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.