gpt4 book ai didi

c++ - Qt Creator 组合框

转载 作者:行者123 更新时间:2023-11-28 02:39:42 24 4
gpt4 key购买 nike

如何将 Combobox 当前文本写入硬盘中已有的文本文件?这是我的代码:

void second::on_pushButton_4_clicked()
{
QFile file("vik.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out << ui->comboBox_5->currentText() << "\n";
}

最佳答案

也许你忘了关闭文件

void second::on_pushButton_4_clicked() 
{
// Get comboBox text value
QString txt = ui->comboBox_5->currentText();

// Open file for writing
QFile file("vik.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);

// Write in file
out << txt << "\n";

// Close file
file.close();
}

关于c++ - Qt Creator 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26390823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com