printf("This machine calculated all prime numbers under %d %d times in %d
seconds\n", MAX_PRIME, NUM_OF_CORES, run_time);
この出力をQMessageBox
テキストボックスに出力します。Qt QMessageBoxに変数値を追加する方法は?
私はQMessageBox
に行ったことがありませんでした。
printf("This machine calculated all prime numbers under %d %d times in %d
seconds\n", MAX_PRIME, NUM_OF_CORES, run_time);
この出力をQMessageBox
テキストボックスに出力します。Qt QMessageBoxに変数値を追加する方法は?
私はQMessageBox
に行ったことがありませんでした。
まず:しかし、QString
はarg
メソッドを使用してプレースホルダを交換し、データをフォーマットするための方法を提供します。方法arg
はQStringで行うことができます。 QMessageBoxの静的メソッドinformationでメッセージボックスを表示することができます。あなたのケースでは、コードは次のようになります。
QMessageBox::information(nullptr/*or parent*/, "Title",
QString("This machine calculated all prime numbers under %1 %2 times in %3 seconds")
.arg(MAX_PRIME).arg(NUM_OF_CORES).arg(run_time));
QMessageBox
は、それがビジネスではないため、何も持っていません。あなたが渡したときに文字列を表示するだけです。あなたQMessageBox
ためQString
を埋める必要があり、すべての
QMessageBox::information(parent,
QString("This machine calculated all prime numbers under %1 %2 times in %3 seconds")
.arg(MAX_PRIME)
.arg(NUM_OF_CORES)
.arg(run_time), "Message title");
[複数の引数を持つ表示QMessageBox]の可能な重複(http://stackoverflow.com/questions/30062868/display-qmessagebox-with-multiple-arguments) – demonplus