2016-06-23 4 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

먼저 당신 QMessageBox에 대한 QString를 작성해야합니다. 방법 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은 비즈니스가 아니기 때문에 아무 것도 사용하지 않습니다. 전달한 문자열 만 표시합니다. 그러나 QStringarg 방법을 사용하여 자리를 대체하는 형식 데이터에 대한 방법을 제공한다 : 모든

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

관련 문제