Problema con archivo de texto
-
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("prueba.txt","a+"); 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); }@
-
will u please state in english ??
-
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"