Results 1 to 4 of 4

Thread: Reading a file/ and calling another window

  1. #1
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Reading a file/ and calling another window

    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

  2. #2
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Reading a file/ and calling another window

    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?

  3. #3
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Angry Re: Reading a file/ and calling another window

    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!

  4. #4
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading a file/ and calling another window

    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?

Similar Threads

  1. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41

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.