2013-08-08 6 views
0

QPushButton이 있는데이 버튼에는 텍스트가 있습니다.이 텍스트는 숫자입니다. 다른 목적의 슬롯 나 버튼에 표시된 숫자를 변경 싶지만 버튼 나던 변화에어떻게 QPushButton에 표시되는 번호를 변경할 수 있습니까?

MyButton->setText(QString("%1").arg(Number)); 

또는

QString tmp; 
tmp.setNum(Number); 
MyButton->setText(tmp); 

텍스트를 호출 할 때. 하지만 전화 할 때

MyButton->setText("some random text"); 

잘 작동합니다. 버튼에 표시되는 번호를 어떻게 바꿀 수 있습니까? 내 코드의

부 : Number

sortWindow::sortWindow(QWidget *parrent) 
{ 
... 
MyButton = new QPushButton; 
QString tmp(QString("%1").arg(Number)); 
MyButton.setText(tmp); 
... 
} 

void sortWindow::workOnSignal(int index) 
{ 
... 
if (something) 
{ 
... 
QString tmp; 
tmp.setNum(Number); 
MyButton->setText(tmp); 
... 
} 
+1

"숫자"의 유형은 무엇입니까? 첫 번째 줄 끝에 ")"이 누락되어 있지만 그저 복사/붙여 넣기 오류 일 뿐이라고 생각합니다. –

+1

디버거 나 qDebug()를 사용하여'tmp'의 값을 확인하십시오. –

+0

Number는 int이고, 네, 첫 줄 끝 부분에서 단지 copy/pste 오류입니다. tmp는 qDebug()를 통해 확인하여 올바른 값을 가짐 –

답변

1

유형 int해야합니다. 그래서 제대로 작동합니다.

#include <QApplication> 
#include <QPushButton> 

int main(int argc,char **argv) 
{ 
    QApplication app(argc,argv); 

    QPushButton *pd = new QPushButton; 
    pd->setText(QString("%1").arg(1234)); 
    pd->show(); 

    return app.exec(); 
} 
관련 문제