qt 소스 질문

bigdaddy2001의 이미지

nNum = 0;
 
    edit = new QLineEdit("", parent);
    edit->setGeometry(rect.x()+0,rect.y()+0,300,40);
 
    button1 = new QPushButton("up", parent);
    button1->setGeometry(rect.x()+305,rect.y()+0,60,40);
 
    button2 = new QPushButton("down", parent);
    button2->setGeometry(rect.x()+365,rect.y()+0,60,40);
 
    connect(button1,SIGNAL(pressed()),this,SLOT(p_up()));
    connect(button2,SIGNAL(pressed()),this,SLOT(p_down()));
 
}
 
void comboWidget::p_up()
{
    nNum++;
    QString temp;
    temp.sprintf("%d", nNum);
 
    edit->setText(temp);
 
    emit minePressed(this, nNum);
 
 
 
}
 
void comboWidget::p_down()
{
    nNum--;
    QString temp;
    temp.sprintf("%d", nNum);
 
    edit->setText(temp);
 
    emit minePressed(this, nNum);
}

대충 이렇게 되어있는데 여기서 nNum의 범위값을 1~10까지 지정하고 그이상 버튼을 눌러도 못올라가게
하려고 합니다 도와주세요

lithium81의 이미지

숫자만 입력받는다 치면 Line Edit 위젯보다 Spin Box나 Double Spin Box 같은 것들이 하한, 상한을 정하기가 무척 쉽습니다.

굳이 Line Edit 위젯을 쓰셔야 한다면, Validator나 정규표현식의 사용을 고려해보십시오...

구글 검색을 하니, 님과 비슷한 질문 하는 분들이 꽤 있네요.

http://www.qtcentre.org/archive/index.php/t-2328.html

http://www.qtforum.org/article/17075/qlineedit-enable-only-number.html

- 어제보다 나은 오늘, 오늘보다 나은 내일.

lithium81의 이미지

아니면 saturation 함수 같은 걸 작성하시면 될 듯 싶네요.

void saturator(int* input)
{
  if(*input > 10)
    *input = 10;
  else if (*input < 1)
    *input = 1;
}

- 어제보다 나은 오늘, 오늘보다 나은 내일.