Results 1 to 5 of 5

Thread: Qfile and QDebug help

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Qfile and QDebug help

    hi I am new to qt and I was following this tutorial and got everything right but I keep getting error's can any one help

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QFile>
    3. #include <QString>
    4. #include <QtDebug>
    5. #include <QTextStream>
    6.  
    7.  
    8. void write(QString filename){
    9. QFile myfile(filename);
    10.  
    11. if(!(myfile.open(QFile::WriteOnly | QFile::Text))){
    12.  
    13. qDebug()<<"Could not write to file ";
    14. return;
    15. }
    16. QTextStream out(&myfile);
    17. out<<"hello world";
    18.  
    19. myfile.flush();
    20. myfile.close();
    21.  
    22. }
    23.  
    24. void read(QString filename){
    25. QFile myfile(filename);
    26.  
    27. if((myfile.open(QFile::ReadOnly | QFile::Text))){
    28.  
    29. qDebug()<<"Could not read file";
    30. return;
    31.  
    32. }
    33.  
    34. QTextStream in(&myfile);
    35. qDebug()<< in.readAll();
    36. myfile.close();
    37.  
    38.  
    39. }
    40.  
    41.  
    42. int main(int argc, char *argv[]){
    43. QApplication app(argc,argv);
    44.  
    45. QString myfile = "c:/qt/tet.txt";
    46.  
    47. write(myfile);
    48. read(myfile);
    49. return app.exec();
    50. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2009
    Location
    India
    Posts
    143
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qfile and QDebug help

    What was the error with the above code ....You haven't mentioned it..

  3. #3
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qfile and QDebug help

    these are the issues that show up

    In function `main':
    undefined reference to `_imp___ZN12QApplicationC1ERiPPci' main.cpp line 41
    undefined reference to `_imp___ZN12QApplication4execEv' main.cpp 47
    undefined reference to `_imp___ZN12QApplicationD1Ev' main.cpp 47
    undefined reference to `_imp___ZN12QApplicationD1Ev' main.cpp 47

  4. #4
    Join Date
    Jun 2009
    Location
    India
    Posts
    143
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qfile and QDebug help


  5. #5
    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: Qfile and QDebug help

    What does your PRO file look like?

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2011, 09:52
  2. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  3. using qdebug
    By GrahamLabdon in forum Newbie
    Replies: 2
    Last Post: 3rd February 2011, 09:59
  4. qDebug() on OSX
    By December in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2008, 17:14
  5. qdebug
    By drkbkr in forum Qt Programming
    Replies: 12
    Last Post: 29th September 2006, 15:26

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.