Results 1 to 12 of 12

Thread: QTextStream readLine() problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QTextStream readLine() problem

    What do you do with pos? Do you use it to seek in the file?
    Can you show more code responsible for reading and navigating in file?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream readLine() problem

    yes, of course.
    The "pos" var is only to see something and always crash in the same position.

    Qt Code:
    1. QCoreApplication a(argc, argv);
    2.  
    3. QStringList args = QCoreApplication::arguments();
    4.  
    5. QRegExp rxArgPath("^--sql_path=(.*)");
    6.  
    7. for (int i = 1; i < args.size(); ++i)
    8. {
    9. //qDebug() << args.at(i);
    10.  
    11. if(rxArgPath.indexIn(args.at(i), 0) == 0)
    12. {
    13. if(!rxArgPath.cap(1).isEmpty())
    14. {
    15. QFile sql_file(rxArgPath.cap(1));
    16.  
    17. if(sql_file.exists())
    18. {
    19. if(sql_file.open(QIODevice::ReadOnly | QIODevice::Text))
    20. {
    21. qDebug() << "reading file " << rxArgPath.cap(1);
    22.  
    23. QTextStream in(&sql_file);
    24. QString line;
    25. int pos = 0;
    26.  
    27. do {
    28. line = in.readLine();
    29. qDebug() << "pos: " << pos << " length: " << line.length();
    30.  
    31. ++pos;
    32. } while (!line.isNull());
    33.  
    34. sql_file.close();
    35. }
    36. }
    37. else
    38. {
    39. qWarning() << "Er: the file " << rxArgPath.cap(1) << "not exists";
    40. }
    41. }
    42. else
    43. {
    44. qWarning() << "Er: Add the path --sql_path";
    45. }
    46. }
    47. }
    48.  
    49. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    thanks in advance

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QTextStream readLine() problem

    Ahh... this all thing is in your main...
    I think that working with QIODevice needs a running event loop (but I am not sure).
    Put this in to a class, and run this code after the event loop is running, that will be a good idea even if its not the problem.
    Maybe some one else can confirm if this is the problem though.

    EDIT:
    [re-edit] I take back what I said here.
    Last edited by high_flyer; 6th January 2011 at 15:00.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Problem quitting QThread that uses readLine
    By DiamonDogX in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2010, 16:43
  2. Qtextstream::readline()
    By dawn_to_dusk_ in forum Qt Programming
    Replies: 4
    Last Post: 3rd August 2008, 17:58
  3. readLine problem
    By gQt in forum Qt Programming
    Replies: 10
    Last Post: 29th February 2008, 09:35
  4. QTextStream, input and readLine()
    By kramed in forum Newbie
    Replies: 6
    Last Post: 1st September 2007, 23:54
  5. QTextStream problem
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2007, 09:50

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.