PDA

View Full Version : Example with errors



fahmi
29th July 2007, 00:22
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:

]
#include <qapplication.h>
#include <qfile.h>
#include <qstring.h>
#include <iostream>
using namespace std;
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QString Filename = "qfile.txt";
if( argc > 1 )
Filename = argv[1];
QFile file Filename );
if( !file.open( IO_ReadOnly ) )
{
cout << "Can't open"
"the file " << Filename
<< endl;
return 0;
}
QString ligne;
while( !file.atEnd() )
{
file.readLine(ligne, 512);
qDebug("%s",ligne.latin1());
}
file.close();
return 0;
}

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::operator<< [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.

jacek
29th July 2007, 01:37
But it generates errors when i compiles it with Qt4.
That's because Qt4 isn't backward compatible with Qt3.


if( !file.open( IO_ReadOnly ) )
It should be QIODevice::ReadOnly.


cout << "Can't open"
"the file " << Filename
<< endl;
Use "qPrintable(Filename)", instead of "Filename".