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 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(); }
-
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(); }
@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 newMainWindow
every time on button click?I want to implement all .txt file in a QcomboBox.
How? Please explain further what you are thinking.
-
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(); }
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.