Results 1 to 6 of 6

Thread: QFileInfoListIterator problem

  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QFileInfoListIterator problem

    Below given is my part of code that used to work some (long) time back. When I need this code, I find it works no more. The compilation is clean, bur when run gives the error as:

    [lx@localhost listDir]$ ./listDir /home/lux/Downloads/xfrd/raw /home/lx/Downloads/xfrd/rawConv/
    04. qStrDir: /home/lx/Downloads/xfrd/raw, qFileInfoDirInfo->fileName: raw01
    05. Before QFileInfoListIterator filesIterator( *filesList ): 0
    Segmentation fault (core dumped)

    The problem seems to be inconsistency by way of new version of the Qt. Please help to make this code work.

    Qt Code:
    1. QDir qDirFindLargest, qDirLargestFile, qDirFilesChange;
    2. QFile qf;
    3. QString qStrDir, qStrDir2, qStrTemp; // a.argv()[i] == argv[i]
    4. qStrTemp = a.argv()[0];
    5. qStrDir = a.argv()[1];
    6. qStrDir2 = a.argv()[2];
    7. //cout << "Total agrc: " << argc << ", Directories 0: " << qStrTemp << ", 1: " << qStrDir << ", 2: " << qStrDir2 << endl;
    8.  
    9. qDirFindLargest.setPath ( qStrDir );
    10. qDirFindLargest.setFilter( QDir::Dirs ); // sets only the directory: shows the directories only
    11. qDirFindLargest.setSorting( QDir::Name | QDir::Reversed );
    12.  
    13. const QFileInfoList *qFileInfoDirList = qDirFindLargest.entryInfoList();
    14. QFileInfoListIterator qFileInfoListIteratorDir( *qFileInfoDirList );
    15. QFileInfo *qFileInfoDirInfo;
    16.  
    17. QString qFileName;
    18. int fileNumber = 0;
    19.  
    20. while ( ( qFileInfoDirInfo = qFileInfoListIteratorDir.current() ) != 0 ) {
    21. if (qFileInfoDirInfo->fileName() == "." ) { // first item in the directory: . (let pass)
    22. ++qFileInfoListIteratorDir;
    23. }
    24. else if (qFileInfoDirInfo->fileName() == ".." ) { // first item in the directory: .. (let pass)
    25. ++qFileInfoListIteratorDir;
    26. }
    27. else {
    28. qDirLargestFile.setPath ( qStrDir + qFileInfoDirInfo->fileName() );
    29. qDirLargestFile.setFilter( QDir::Files ); // qFiles to only show the files
    30. qDirLargestFile.setSorting( QDir::Name | QDir::Reversed ); // sorting the files in the directory in reverse order: to find the last file alphabetically
    31. cout << "04. qStrDir: " << qStrDir << ", qFileInfoDirInfo->fileName: " << qFileInfoDirInfo->fileName() << endl;
    32. const QFileInfoList *filesList = qDirLargestFile.entryInfoList();
    33. cout << "05. Before QFileInfoListIterator filesIterator( *filesList );" << endl;
    34.  
    35. QFileInfoListIterator filesIterator( *filesList );
    36. cout << "06. After QFileInfoListIterator filesIterator( *filesList );" << endl;
    37. QFileInfo *files;
    38. cout << "07. After QFileInfo *files;" << endl;
    39. files = filesIterator.current();
    40. cout << "07A. After files = filesIterator.current(), files = filesIterator.current(): " << filesIterator.current() << endl;
    41. cout << "08. After files = filesIterator.current(), files->fileName: " << files->fileName() << endl;
    42.  
    43. ... }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileInfoListIterator problem

    Qt Code:
    1. QFileInfoListIterator filesIterator( *filesList );
    To copy to clipboard, switch view to plain text mode 
    You are dereferencing a pointer without checking if it's not NULL, this could be dangerous.

    I'm also curious, what is your Qt version and compiler, because as far as I'm concerned, this code should not compile:
    Qt Code:
    1. const QFileInfoList *filesList = qDirLargestFile.entryInfoList();
    To copy to clipboard, switch view to plain text mode 
    QDir::entryInfoList() returns QFileInfoList, not QFileInfoList *

  3. #3
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QFileInfoListIterator problem

    Thanks for the reply.

    As I mentioned this code worked long back & now it is complaining. What you mention that it should not compile may also be right. But if I change as per your observation it does not compile. "QDir::entryInfoList() returns QFileInfoList, not QFileInfoList * " Hence, it seems what is coded is compile proof.

    Any more ideas? Actually I am out of touch for quite some time now, and I could sure use some help.

    Thanks once more.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileInfoListIterator problem

    Please answer the question "what is your Qt version and compiler?"

  5. #5
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QFileInfoListIterator problem

    Qt Designer Version: 4.7.1

    qmake -v
    Qmake version: 1.07a (Qt 3.3.8b)
    Qmake is free software from Trolltech ASA.

    make -v
    GNU Make 3.82
    Built for i386-redhat-linux-gnu
    Copyright (C) 2010 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFileInfoListIterator problem

    You claim to be using Qt 4.7.1 but the qmake you tell us about is from Qt 3 and QFileInfoListIterator is a Qt3 item. Has the code been ported to Qt4 using the Qt 3 Support module or should you be using the Qt3 tool set? Have you tried to mix code previously built with Qt 3 with Qt 4 components?

Similar Threads

  1. Q3PtrList & QFileInfoListIterator ??
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 08:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.