[Qt-interest] How to avoid absolute file locations
Samuel G
samuel857 at gmail.com
Sat Jan 10 02:47:22 CET 2009
----------------mydata.txt----------------
2
3
----------------read.cpp----------------
#include <QtGlobal>
#include <QFile>
#include <QTextStream>
int main()
{
QFile file("mydata.txt");
Q_ASSERT( file.open(QIODevice::ReadOnly | QIODevice::Text) ); // line 8
QTextStream in(&file);
int i, j;
in >> i >> j;
Q_ASSERT( i+j == 5 ); // line 14
}
----------------end----------------
With the two files above, opening the file fails on line 8. What is
the Qt way to read program data without using an absolute file
location?
Relocatable code makes it possible for others with whom I share my code
to run it unmodified, and also allows me to run the same project in
different locations or on more than one computer.
Samuel
More information about the Qt-interest-old
mailing list