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. debug variable
Forum Updated to NodeBB v4.3 + New Features

debug variable

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 289 Views
  • 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.
  • AlbatorA Offline
    AlbatorA Offline
    Albator
    wrote on last edited by
    #1

    Hello qt people :) ,

    i have a little pbl :'(
    i'don't understand why the qvector<qstring> is empty !
    if you have any idea

        QVector<QString> vector;
        vector << "observation" << "diag" << "ca" << "pa";
    
        QVector<QString> all_ligne,all_ligne1,all_ligne2,all_ligne3;
    
    for(int p=0;p<4;p++)
    {
    
        QFile file(path_app+"/report/"+vector.at(p)+".txt");
    
    
        QString ligne;
    
        file.resize(0); // to flush
    
        if (file.open(QIODevice::ReadWrite)) {
    
            QTextStream stream(&file);
    
    
            if(p==0)
            stream << ui->observation->toPlainText(); //qtextedit
            if(p==1)
            stream << ui->diag->toPlainText();
            if(p==2)
            stream << ui->ca->toPlainText();
            if(p==3)
            stream << ui->pa->toPlainText();
    
    
    
            while(!stream.atEnd()) {
    
                ligne = stream.readLine();
    
                if(p==0)
                all_ligne.append(ligne);
                if(p==1)
                all_ligne1.append(ligne);
                if(p==2)
                all_ligne2.append(ligne);
                if(p==3)
                all_ligne3.append(ligne);
    
    
                }
    
    
    
            file.flush();
    
    
            file.close();
    
    
    
        }
        else {
            QMessageBox::critical(this, tr("Error"), tr("Double ouverture"));
            return;
        }
    
    
    
    }
    
    qDebug() << all_ligne.size() << all_ligne;
    

    this code is in a qpushbutton so :
    first shot - QVector()
    second shot - 0 QVector("test")

    why in the first shot he not take the value ?

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • AlbatorA Albator

      Hello qt people :) ,

      i have a little pbl :'(
      i'don't understand why the qvector<qstring> is empty !
      if you have any idea

          QVector<QString> vector;
          vector << "observation" << "diag" << "ca" << "pa";
      
          QVector<QString> all_ligne,all_ligne1,all_ligne2,all_ligne3;
      
      for(int p=0;p<4;p++)
      {
      
          QFile file(path_app+"/report/"+vector.at(p)+".txt");
      
      
          QString ligne;
      
          file.resize(0); // to flush
      
          if (file.open(QIODevice::ReadWrite)) {
      
              QTextStream stream(&file);
      
      
              if(p==0)
              stream << ui->observation->toPlainText(); //qtextedit
              if(p==1)
              stream << ui->diag->toPlainText();
              if(p==2)
              stream << ui->ca->toPlainText();
              if(p==3)
              stream << ui->pa->toPlainText();
      
      
      
              while(!stream.atEnd()) {
      
                  ligne = stream.readLine();
      
                  if(p==0)
                  all_ligne.append(ligne);
                  if(p==1)
                  all_ligne1.append(ligne);
                  if(p==2)
                  all_ligne2.append(ligne);
                  if(p==3)
                  all_ligne3.append(ligne);
      
      
                  }
      
      
      
              file.flush();
      
      
              file.close();
      
      
      
          }
          else {
              QMessageBox::critical(this, tr("Error"), tr("Double ouverture"));
              return;
          }
      
      
      
      }
      
      qDebug() << all_ligne.size() << all_ligne;
      

      this code is in a qpushbutton so :
      first shot - QVector()
      second shot - 0 QVector("test")

      why in the first shot he not take the value ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Albator said in debug variable:

      i'don't understand why the qvector<qstring> is empty !

      How do you know it is empty? So, what happens?
      Also, can you please post whole code and not just this snippet as it is not clear where vector is actually initialised.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • AlbatorA Albator

        Hello qt people :) ,

        i have a little pbl :'(
        i'don't understand why the qvector<qstring> is empty !
        if you have any idea

            QVector<QString> vector;
            vector << "observation" << "diag" << "ca" << "pa";
        
            QVector<QString> all_ligne,all_ligne1,all_ligne2,all_ligne3;
        
        for(int p=0;p<4;p++)
        {
        
            QFile file(path_app+"/report/"+vector.at(p)+".txt");
        
        
            QString ligne;
        
            file.resize(0); // to flush
        
            if (file.open(QIODevice::ReadWrite)) {
        
                QTextStream stream(&file);
        
        
                if(p==0)
                stream << ui->observation->toPlainText(); //qtextedit
                if(p==1)
                stream << ui->diag->toPlainText();
                if(p==2)
                stream << ui->ca->toPlainText();
                if(p==3)
                stream << ui->pa->toPlainText();
        
        
        
                while(!stream.atEnd()) {
        
                    ligne = stream.readLine();
        
                    if(p==0)
                    all_ligne.append(ligne);
                    if(p==1)
                    all_ligne1.append(ligne);
                    if(p==2)
                    all_ligne2.append(ligne);
                    if(p==3)
                    all_ligne3.append(ligne);
        
        
                    }
        
        
        
                file.flush();
        
        
                file.close();
        
        
        
            }
            else {
                QMessageBox::critical(this, tr("Error"), tr("Double ouverture"));
                return;
            }
        
        
        
        }
        
        qDebug() << all_ligne.size() << all_ligne;
        

        this code is in a qpushbutton so :
        first shot - QVector()
        second shot - 0 QVector("test")

        why in the first shot he not take the value ?

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @Albator said in debug variable:

        i'don't understand why the qvector<qstring> is empty !

        Perhaps you have to go to file begin after writing to be able to read it ;)
        Add something like this before to reading loop:

        stream.flush(); // to write all to the file
        stream.seek(0); // go to file begining
        while(!stream.atEnd()) {
        ...
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        AlbatorA 1 Reply Last reply
        4
        • KroMignonK KroMignon

          @Albator said in debug variable:

          i'don't understand why the qvector<qstring> is empty !

          Perhaps you have to go to file begin after writing to be able to read it ;)
          Add something like this before to reading loop:

          stream.flush(); // to write all to the file
          stream.seek(0); // go to file begining
          while(!stream.atEnd()) {
          ...
          }
          
          AlbatorA Offline
          AlbatorA Offline
          Albator
          wrote on last edited by
          #4

          @KroMignon

          arf it was so simple, you just had to go back to the beginning of the doc...

          thank you :)

          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