Results 1 to 2 of 2

Thread: Qt counting error

  1. #1
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt counting error

    I have 2 push button, one for increment & the other for decrement & a label to display result. I use this setup in 2 different places. But in some odd cases, the counter seems to be increasing at the rate of 16(0,16,32..etc). I'm not sure why this is happening. What am i doing wrong here. Is there an easier/simple way of doing this?

    Qt Code:
    1. int count2; (declared in a .h file, as a public variable)
    2.  
    3. connect(this->ui->pb_inc, SIGNAL(clicked()), this, SLOT(inc()));
    4. connect(this->ui->pb_dec, SIGNAL(clicked()), this, SLOT(dec()));
    5.  
    6. void MainWindow::inc()
    7. {
    8. count2=count2+1;
    9. this->ui->label_count->setText(QString("%1").arg(count2));
    10. }
    11.  
    12. void MainWindow::dec()
    13. {
    14. count2=count2-1;
    15. if(count2<=0) count2=0;
    16. this->ui->label_count->setText(QString("%1").arg(count2));
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 9th September 2011 at 01:04. Reason: missing [code] tags

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Qt counting error

    Does this help?

    Qt Code:
    1. connect(this->ui->pb_inc, SIGNAL(clicked()), this, SLOT(inc()),Qt::UniqueConnection);
    2. connect(this->ui->pb_dec, SIGNAL(clicked()), this, SLOT(dec()),Qt::UniqueConnection);
    To copy to clipboard, switch view to plain text mode 
    Don't write a post just to thank someone, use "Thanks" button.

  3. The following user says thank you to Rachol for this useful post:

    premroxx (9th September 2011)

Similar Threads

  1. : error: [\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\V ideo.exe] Error 1
    By ranjit.kadam in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st May 2011, 22:11
  2. Counting and looping properties
    By stefan in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2011, 13:38
  3. counting controls in a form with its childs ?
    By hcetiner in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2010, 19:14
  4. Counting flags in a bit mask
    By Lykurg in forum General Programming
    Replies: 1
    Last Post: 24th July 2009, 10:53
  5. [QT4] Counting files in a directory (Linux)
    By ucntcme in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 22:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.