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. Robust Reading a text file

Robust Reading a text file

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 652 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.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings.

    I'm reading a text file with QFile and QTextStream and although I do not generate any error the testing I've done, I want my code is robust and handles any errors that may appear during reading (for example, that in the input file has less data than expected).

    The problem is that not exactly how to do that (make the code is sufficiently robust to signal that an error occurred during the reading), or rather do not know if I'm doing okay so far.

    What I'm doing is (roughly) the following:

    @
    QFile arch("inputFile.in");

    if( !arch.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        //Give appropriate error message and exit
    }
    
    
    QTextStream entrada( &arch );
    while( (entrada.status() == QTextStream::Ok) && !entrada.atEnd() )
    {
        //Read the input data
        entrada >> dat1 >> dat2;
        ...
        entrada >> datN;
    
        //Process the data read...
    }
    
    
    if( entrada.status() != QTextStream::Ok )
    {
        //Give appropriate error message and exit
    }
    

    @

    Is it right or what I'm doing works?.
    Is it efficient or is the best way?.

    Thanks in advance for any responses and/or comments.

    Isaac Pérez
    Programming is understanding.

    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