Results 1 to 2 of 2

Thread: Example with errors

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

    Default Example with errors

    Hello,
    I am trying to test an example from a book that is done with Qt3.
    But it generates errors when i compiles it with Qt4.
    This is the example:
    Qt Code:
    1. ]
    2. #include <qapplication.h>
    3. #include <qfile.h>
    4. #include <qstring.h>
    5. #include <iostream>
    6. using namespace std;
    7. int main( int argc, char **argv )
    8. {
    9. QApplication a( argc, argv );
    10. QString Filename = "qfile.txt";
    11. if( argc > 1 )
    12. Filename = argv[1];
    13. QFile file Filename );
    14. if( !file.open( IO_ReadOnly ) )
    15. {
    16. cout << "Can't open"
    17. "the file " << Filename
    18. << endl;
    19. return 0;
    20. }
    21. QString ligne;
    22. while( !file.atEnd() )
    23. {
    24. file.readLine(ligne, 512);
    25. qDebug("%s",ligne.latin1());
    26. }
    27. file.close();
    28. return 0;
    29. }
    To copy to clipboard, switch view to plain text mode 
    and generated errors are:
    a.cpp:13: erreur: ‘IO_ReadOnly’ was not declared in this scope
    a.cpp:16: erreur: no match for ‘operator<<’ in ‘std:perator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Impossible d\37777777742\37777777600\37777777631Can't open the file ")) << Filename’
    a.cpp:23: erreur: no matching function for call to ‘QFile::readLine(QString&, int)’
    a.cpp:24: erreur: ‘class QString’ has no member named ‘latin1’
    make: *** [a.o] Erreur 1

    In fact, i have tried to solve this errors using the docs of Qt4 but i can't.
    Help please.
    Last edited by jacek; 29th July 2007 at 01:29. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Example with errors

    Quote Originally Posted by fahmi View Post
    But it generates errors when i compiles it with Qt4.
    That's because Qt4 isn't backward compatible with Qt3.

    Quote Originally Posted by fahmi View Post
    if( !file.open( IO_ReadOnly ) )
    It should be QIODevice::ReadOnly.

    Quote Originally Posted by fahmi View Post
    cout << "Can't open"
    "the file " << Filename
    << endl;
    Use "qPrintable(Filename)", instead of "Filename".

Similar Threads

  1. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  2. Qt compilation errors
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2006, 17:29
  3. Qt Compile Errors?
    By magikalpnoi in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2006, 22:18
  4. Linker Errors
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2006, 18:30
  5. Qt 4.1.0 - static examples run with errors!
    By Elder Orb in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2006, 09:40

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.