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. need to create multiple .txt files
Forum Updated to NodeBB v4.3 + New Features

need to create multiple .txt files

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 160 Views 2 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.
  • R Offline
    R Offline
    Ruben12313
    wrote on last edited by
    #1

    so in c++ i was able to create multiple .txt file in my folder and in Qt i want that same thing for every time the save button is pressed. Each .txt file is going to store student names and I want to implement all .txt file in a QcomboBox.

    void AddingText::on_Saveb_clicked()
    {
            int i=1;
            std::string name, grade, gpa;
            QString fname = ("C:\\project\\"+std::string{"Student"} + std::to_string(i) + ".txt");
            QFile file(fname);
            if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
            {
                QTextStream stream(&file);
                QString file = ui->lineEditName->text();
                stream << file <<"\n";
    
    
            }
    
            i++;
    
            file.close();
            hide();
            ptrsave = new MainWindow(this);
            ptrsave->show();
    
    }
    
    
    Pl45m4P artwawA 2 Replies Last reply
    0
    • R Ruben12313

      so in c++ i was able to create multiple .txt file in my folder and in Qt i want that same thing for every time the save button is pressed. Each .txt file is going to store student names and I want to implement all .txt file in a QcomboBox.

      void AddingText::on_Saveb_clicked()
      {
              int i=1;
              std::string name, grade, gpa;
              QString fname = ("C:\\project\\"+std::string{"Student"} + std::to_string(i) + ".txt");
              QFile file(fname);
              if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
              {
                  QTextStream stream(&file);
                  QString file = ui->lineEditName->text();
                  stream << file <<"\n";
      
      
              }
      
              i++;
      
              file.close();
              hide();
              ptrsave = new MainWindow(this);
              ptrsave->show();
      
      }
      
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Ruben12313 said in need to create multiple .txt files:

      so in c++ i was able to create multiple .txt file in my folder and in Qt i want that same thing

      There is no "in Qt". Qt is still a C++ framework.

      ptrsave = new MainWindow(this);

      What is this in this case?
      Why create a new MainWindow every time on button click?

      I want to implement all .txt file in a QcomboBox.

      How? Please explain further what you are thinking.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • R Ruben12313

        so in c++ i was able to create multiple .txt file in my folder and in Qt i want that same thing for every time the save button is pressed. Each .txt file is going to store student names and I want to implement all .txt file in a QcomboBox.

        void AddingText::on_Saveb_clicked()
        {
                int i=1;
                std::string name, grade, gpa;
                QString fname = ("C:\\project\\"+std::string{"Student"} + std::to_string(i) + ".txt");
                QFile file(fname);
                if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
                {
                    QTextStream stream(&file);
                    QString file = ui->lineEditName->text();
                    stream << file <<"\n";
        
        
                }
        
                i++;
        
                file.close();
                hide();
                ptrsave = new MainWindow(this);
                ptrsave->show();
        
        }
        
        
        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by artwaw
        #3

        @Ruben12313

        I gather you want to see list of file names in that combo box? You can use QStringList to store and assign content to QComboBox, my gut reflex would be to use QStringListModel - this would allow for better management and stress free updates to the view (as any change in the model would be visible in every view the model is connected to).
        Please provide an overview of use case - what would you like to achieve in terms of functionality? This way we can hint you more correctly.

        And as @Pl45m4 wrote - that prtsave part is bizzare and most likely incorrect.

        For more information please re-read.

        Kind Regards,
        Artur

        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