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. Problema con archivo de texto
Qt 6.11 is out! See what's new in the release blog

Problema con archivo de texto

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 914 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
    shikamarucb
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      ankursaxena
      wrote on last edited by
      #2

      will u please state in english ??

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shikamarucb
        wrote on last edited by
        #3

        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
        0

        • Login

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