Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Creating Database text file based application
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Creating Database text file based application

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sirsanndy
    wrote on 25 Mar 2014, 06:25 last edited by
    #1

    Hey, I'm sandy. I'm very newbie on C++ and Qt.
    I've homework from computer class to build database text file based application for the mid of semester.
    Read, add, delete database application.
    My teacher waives any student to use any programming languages.
    I choose C++ and Qt for my homework.
    This is the field of my database :
    code
    name
    gender

    all of my data store to text file. separating by "#" on every field and "\n" for every record.

    First I learn to show the text file on textBrowser and success (include messagebox if file missing and create file "contact.txt").

    This is printscreen of my application :
    !http://www.qtcentre.org/attachment.php?attachmentid=10166&d=1395728497(Form)!

    and this is the textBrowser :
    !http://www.qtcentre.org/attachment.php?attachmentid=10167&d=1395728521(textBrowser)!

    For the next step I've to get value from line edit(code and name) and radio button(for gender) store it to "contact.txt" and if "contact.txt" isn't null to store the value to the next line of the text file.
    how to do it ?

    Sorry if my english so bad, isn't my native.
    Thank you.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on 25 Mar 2014, 08:07 last edited by
      #2

      For appending data to file you can use
      @QString fileName = "contact.txt";
      QFile file(fileName);

      if(!file.open(QFile::Append | QFile::Text)){
          qDebug() << "not open";
          return 0;
      }
      
      QTextStream out(&file);
      out << DataString<< "\n";
      
      file.close();@
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        sirsanndy
        wrote on 25 Mar 2014, 09:21 last edited by
        #3

        Thank you, solved after go to manual. And before read your reply, but thanks !
        Here is my code :

        @void tampilan::on_simpan_clicked()
        {
        QString pinData, nameData;
        pinData = ui->pinEdit->text();
        nameData = ui->nameEdit->text();
        QFile kontak("kontak.txt");
        if(!kontak.open(QIODevice::ReadWrite)){
        QMessageBox::information(0,"info",kontak.errorString());
        }
        QTextStream update(&kontak);
        QString line;
        do{
        line = update.readLine();
        }while(!line.isNull());
        update <<"#"<< pinData;
        update <<"#"<< nameData;
        if(ui->radioMale->isChecked()==true){
        update <<"#M";
        }else if(ui->radioFemale->isChecked()==true){
        update <<"#F";
        }
        update <<"\n";
        kontak.close();
        if(!kontak.open(QIODevice::ReadOnly)){
        QMessageBox::information(0,"info",kontak.errorString());
        }
        ui->pinEdit->clear();
        ui->nameEdit->clear();
        ui->radioMale->setChecked(true);
        QTextStream in(&kontak);
        ui->textBrowser->setText(in.readAll());
        }@

        1 Reply Last reply
        0

        1/3

        25 Mar 2014, 06:25

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved