2016-06-23 62 views
0
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に行ったことがありませんでした。

+0

[複数の引数を持つ表示QMessageBox]の可能な重複(http://stackoverflow.com/questions/30062868/display-qmessagebox-with-multiple-arguments) – demonplus

答えて

1

まず:しかし、QStringargメソッドを使用してプレースホルダを交換し、データをフォーマットするための方法を提供します。方法argQStringで行うことができます。 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)); 
2

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"); 

http://doc.qt.io/qt-5/qstring.html#argument-formats

http://doc.qt.io/qt-5/qstring.html#arg

関連する問題