PDA

View Full Version : Qt meego txt file not read



m.azeemanwar
27th December 2011, 13:02
hi
i wanna to read a .txt file in QT my file is place in qml folder .but i failed..rememer this code is running good for symbian and desktop application
am i wrong at somewhere plz let me know here is code .....Test2 is my project name

void GraphicsEngine::loadPawnLocations(){
// bool isComment = false;
QString sToken;
int index;
int x_pos = 0;
int y_pos = 0;

QFile file("qml/Test2/pawnPosition.txt");

QStringList strings;

if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{

QTextStream in(&file);
char tmp;
in>>index;
in>>tmp;
in>>x_pos;
in>>tmp;
in>>y_pos;
while (!in.atEnd() ) {

if (index >= PathMap::JOURNY_CELLS
&& index < PathMap::JOURNY_CELLS + PathMap::HOME_STREET_CELLS) {

pawnsInHomeStreet[index
- PathMap::JOURNY_CELLS][X_POS] = x_pos;
pawnsInHomeStreet[index
- PathMap::JOURNY_CELLS][Y_POS] = y_pos;

} /**
* locations for the pawns in castle
* */
else if (index
>= PathMap::JOURNY_CELLS + PathMap::HOME_STREET_CELLS) {
pawnsInCastleLocations[index - PathMap::JOURNY_CELLS
- PathMap::HOME_STREET_CELLS][X_POS] = x_pos;
pawnsInCastleLocations[index - PathMap::JOURNY_CELLS
- PathMap::HOME_STREET_CELLS][Y_POS] = y_pos;

} /**
* Normally traveling
* */
else {
pawnLocations[index][X_POS] = x_pos;
pawnLocations[index][Y_POS] = y_pos;
}
strings.clear();

in>>index;
in>>tmp;
in>>x_pos;
in>>tmp;
in>>y_pos;



}
}else
{
exit(1);
// qDebug()<<"file not open";
}
}

mvuori
27th December 2011, 22:19
The problems: You do not have any attempt at finding where the problem is -- the system finding the file or reading it.
Most likely problem: you have a relative path, which is relative to your current directory, which probably is something other than you assume. Try using a full path for your file.