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;
}

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.