Results 1 to 4 of 4

Thread: Reading a .pro file using custom read function

  1. #1
    Join Date
    Sep 2017
    Posts
    23
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Reading a .pro file using custom read function

    I am trying to read the .pro file of my project and display it on the console window. The reading was done successfully but the displaying was not as expected. The program displays the text as sequential letters:

    Qt Code:
    1. QT += core\nQT -= gui\nCONFIG += c++11\nTARGET = 13-ResourceFiles\nCONFIG += console\nCONFIG -= app_bundle\nTEMPLATE = app\n\nSOURCES += main.cpp\n\n
    To copy to clipboard, switch view to plain text mode 

    not as :
    Qt Code:
    1. QT += core
    2. QT -= gui
    3.  
    4.  
    5. CONFIG += c++11
    6.  
    7. TARGET = 13-ResourceFiles
    8. CONFIG += console
    9. CONFIG -= app_bundle
    10. TEMPLATE = app
    11.  
    12. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    Here is the Reading function:
    Qt Code:
    1. void Read(QString file_name)
    2. {
    3. QFile myfile(file_name);
    4. if(myfile.exists())
    5. {
    6. myfile.open(QIODevice::ReadOnly);
    7. QString my_buffer;
    8. my_buffer=myfile.readAll();
    9. qDebug()<<my_buffer;
    10. myfile.flush();
    11. myfile.close();
    12. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Reading a .pro file using custom read function

    Try this:

    Qt Code:
    1. void Read(QString file_name)
    2. {
    3. QFile myfile(file_name);
    4. if(myfile.exists())
    5. {
    6. if(myfile.open(QIODevice::ReadOnly)){
    7. QTextStream stream(&myfile);
    8. QString my_buffer = stream.realAll();
    9. qDebug()<<my_buffer;
    10. myfile.close();
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Using readAll() is not recommended unless you can assert that the size of the read files is not very large.
    ==========================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.

  3. #3
    Join Date
    Sep 2017
    Posts
    23
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reading a .pro file using custom read function

    I can not see any difference in the result. what did you modify?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading a .pro file using custom read function

    QDebug escapes non-printable characters. Try to change qDebug() with qDebug().noquote().

Similar Threads

  1. Replies: 18
    Last Post: 7th August 2015, 15:53
  2. Replies: 0
    Last Post: 10th March 2010, 08:13
  3. Replies: 3
    Last Post: 18th October 2007, 18:07
  4. Function for reading and writing
    By merry in forum Newbie
    Replies: 2
    Last Post: 30th May 2007, 08:30
  5. Replies: 1
    Last Post: 16th October 2006, 07:25

Tags for this Thread

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.