Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Problema con archivo de texto

    General and Desktop
    2
    3
    714
    Loading More Posts
    • 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
      shikamarucb last edited by

      hola a todos, tengo el siguiente codigo en QTCREATOR y lo que pasa es que me esta escribiendo 2 veces los datos en el archivo de texto cada vez que hago un click en el push button, como si le hiciera dos clicks al push buton. Me estaria quedando el archivo del doble de tamaño cada vez que escribe en el archivo. La idea seria usar el manejo de archivos de “C” y “C++” pero no se porque sucede esto. Le puse un contador y efectivamente en cada click repite dos veces el "SLOT"

      @ //pruebin.cpp
      #include "pruebin.h"
      #include "ui_pruebin.h"
      #include <string>
      using namespace std;

          pruebin::pruebin(QWidget *parent) :
              QWidget(parent),
              ui(new Ui::pruebin)
          {
              ui->setupUi(this);
              connect(ui->pushButton,SIGNAL(clicked()),SLOT(on_pushButton_clicked()));
          }
           
          pruebin::~pruebin()
          {
              delete ui;
          }
          FILE *arc;
           
          struct datos{
              char name[30];
              char edad[2];
              char peso[2];
          };
          datos dat;
           
          void pruebin::on_pushButton_clicked() //SLOT de la señal clicked
          {
              arc=fopen&#40;"prueba.txt","a+"&#41;;
              QString nam=ui->lineEdit->text();
              QString edd=ui->lineEdit_2->text();
              QString pes=ui->lineEdit_3->text();
           
              string nnn=nam.toStdString();
              string eee=edd.toStdString();
              string ppp=pes.toStdString();
           
              strncpy(dat.name,nnn.c_str(),sizeof(dat.name));
              strncpy(dat.edad,eee.c_str(),sizeof(dat.edad));
              strncpy(dat.peso,ppp.c_str(),sizeof(dat.peso));
           
              fwrite(&dat,sizeof(dat),1,arc);
              fclose(arc);
          }@
      
      1 Reply Last reply Reply Quote 0
      • A
        ankursaxena last edited by

        will u please state in english ??

        1 Reply Last reply Reply Quote 0
        • S
          shikamarucb last edited by

          I do not speak English, I will use the google translator.

          Hi all, I have the following code in QtCreator and what happens is that I is writing 2 times the data in the text file every time I click on the push button, as if you make two clicks to push buton. I would be running the file twice the size each time you write to the file. The idea would be to use the file handling "C" and "C + +" but do not know why this happens. I put a counter on each click and effectively repeated twice "SLOT"

          1 Reply Last reply Reply Quote 0
          • First post
            Last post