PDA

View Full Version : Reading a file/ and calling another window



Gummie
15th August 2009, 14:04
Hi there,

Trying to read text out a .dat file I created but not having much luck... now trying code direct from trolltech site!:
bool ItemReader::read(ItemList* iList){
QFile file(fileName);
QDir::setCurrent("/TheStore");
file.setPermissions(QFile::ReadUser);
if(!file.open(QIODevice::ReadOnly|QIODevice::Text) ){
qDebug()<<"File not opening" << endl;
return false;
}
QTextStream in(&file);
QString line = in.readLine();
while(!line.isNull()){
QStringList itemProps =line.split(QRegExp("\\t"));
Item *addChild= new Item((itemProps.at(0)).toInt(),itemProps.at(1),ite mProps.at(2),(itemProps.at(3)).toInt());
iList->add(addChild);
line = in.readLine();
qDebug()<< line << endl;
//QString s =itemProps.at(1);
//qDebug() << s << endl;
//Item *one = new Item(0000,"fruit","apple",1);
//iList->add(one);
}
file.close();
qDebug() << "Read it!!" << endl;
return true;
}


Then want to call a QMainWindow SalesScreen from the main app Login.... but it flashes and does not stay on the screen... do I need to transfer control somehow?Q!
void Login::validate(){
if(valAdmin.exactMatch(enterPassword->text())){
result->setText("Administrator logged on");
}
else if(valSales.exactMatch(enterPassword->text())){
result->setText("Sales assistant logged on");
SalesScreen sale;
sale.setGui();
}
else if(valManager.exactMatch(enterPassword->text())){
result->setText("Manager logged on");
}
else{
enterPassword->clear();
result->setText("Invalid Login : enter password again");
}

}

Any help would be greatly appreciated :)

Archimedes
17th August 2009, 03:26
From what you said I guess there's a login dialog waiting for input and you want to show the main window after the user validation .
Connecting the dialog signal accepted() with the main window's slot show() works for me.

According the file read, the code you posted seems right. What exactly is the problem there? Are the classes Item and iList handle the data correct?

Gummie
17th August 2009, 08:13
Ok... at work at the moment so will look at it later again.... I am not calling it through signals and slots at the moment. I call validate() after returnPressed() using signals and slots and depening on who logs in I call the constructor of that particular screen.....

Part 2 - reading the file.... I know the ItemList is working as I can add items using add(Item* i) but when trying to add Items from a file the list comes up empty.... the file is being opened but it is not reading the contents - super frustrating!

Gummie
19th August 2009, 13:07
ok... solved - reading the file. saving the file in Notepad instead of wordpad worked.... can anyone help with why I can't get a window to stay when I call it from my login app?:confused: