[英]I can't seem to print several lines of data in qt creator. Program overwrites all output except for the last line
我的預期輸出:打印指數方程式的時間和細菌數。 我試圖打印直到時間t的每個數據點,例如,如果我發現直到50小時的增長,我想打印時間0、1、2,...,49的細菌數,50。我也試圖將每個輸出都換行。
void MainWindow::on_pushButtonCalc_clicked()
{
QString s;
double t = ui->t->text().toDouble();
double k = ui->k->text().toDouble();
double n0 = ui->n0->text().toDouble();
/*double example;
example= k;
s = s.number(example);
ui->textOutput->setText(s);*/
for(int c = 0; c<t; ++c)
{
double nt = n0*exp(k*t);
s = s.number(nt);
ui->textOutput->setText(s);
}
}
我嘗試了很多不同的輸出,並且還嘗試將新的點添加到數組並打印該數組,但是我也沒有那么幸運。 我對C ++有點陌生,對qt也很陌生。
感謝您的任何建議。
QTextEdit::setText
函數將用您傳入的參數替換文本編輯的內容。相反,您可以使用append
函數:
for(int c = 0; c<t; ++c)
{
double nt = n0*exp(k*t);
s = QString::number(nt);
ui->textOutput->append(s);
}
還要注意,由於QString::number
是靜態函數,因此不需要實例來調用它。
或者,您可以在循環中創建字符串,然后使用setText
將其設置為文本編輯:
for (int c = 0; c<t; ++c)
{
double nt = n0*exp(k*t);
s += QString("%1 ").arg(nt);
}
ui->textOutput->setText(s);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.