QStringList list = ui.tedLog->toPlainText().split("\n")
再循环取 list写入文件就可以了。
长了脑子是要用的。打开QtCreator的帮助页面,找到
Qt Reference Documentation ---》Classes--》QLineEdit Class Reference
看到QLineEdit的帮助文档,
Signals
void cursorPositionChanged ( int old, int new )
void editingFinished ()
void returnPressed ()
void selectionChanged ()
void textChanged ( const QString &text )
void textEdited ( const QString &text )
textEdited()是一个信号,不是函数,不能干任何事,这是用于触发其他槽函数的。
获取文本的函数:
Public Functions
QString text () const
获取文本用lineEdit->text()
这么简单都不用脑子?
Access functions:访问文本的函数
QString text () const
void setText ( const QString &)
Notifier signal:通知信号
void textChanged ( const QString &text )
1、HeatUser类
class HeatUser{
public:
HeatUser(){
}
HeatUser(QString name, float flow, float distance, short time){
strcpy(Name, name.toLocal8Bit().data())
Flow = flow
Distance = distance
Time = time
}
~HeatUser(){
}
QString getName(){
return Name
}
QString getFlow(){
return QString("%1").arg(Flow)
}
QString getDistance(){
return QString("%1").arg(Distance)
}
QString getTime(){
return QString("%1").arg(Time)
}
private:
char Name[30]
float Flow
float Distance
short Time
}
2、对象初始化
QFile file("aa.txt")if(file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file)
while(!stream.atEnd())
{
QStringList list = stream.readLine().split(QRegExp("\\s+"))
HeatUser hUser(list.at(0), static_cast<QString>(list.at(1)).toFloat(),
static_cast<QString>(list.at(2)).toFloat(),
static_cast<QString>(list.at(3)).toShort())
vec.push_back(hUser)
}
}
3、文件内容
aa 126.0 22.6 99bb 165.0 23.6 100
4、写入Qtablewidget
ui->tableWidget->setRowCount(2) //设置行数为2ui->tableWidget->setColumnCount(4) //设置列数为4
QStringList header
header << "Name" << "Flow" << "Distance" << "Time"
ui->tableWidget->setHorizontalHeaderLabels(header)
for(int i = 0 i < vec.count() i++)
{
ui->tableWidget->setItem(i,0,new QTableWidgetItem(vec[i].getName()))
ui->tableWidget->setItem(i,1,new QTableWidgetItem(vec[i].getFlow()))
ui->tableWidget->setItem(i,2,new QTableWidgetItem(vec[i].getDistance()))
ui->tableWidget->setItem(i,3,new QTableWidgetItem(vec[i].getTime()))
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)