Danny Fan
8th March 2011, 20:54
Hi All,
I start to learn the QT but I have some problem with an example that I'm try to develop.
This is the part of the code
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QIntegerForSize"
#include "QTimer"
#include "QLabel"
#include "QString"
#include "mainwindow.h"
int a;
int c;
bool b;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::GreenUnoClick()
{
if (b != true)
{
a = (a*10) + 1;
}
else
{
c = ui->lcdNumber->intValue();
a = 1;
}
b = true;
ui->lcdNumber->display(a);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(AddValueLCD()));
timer->setSingleShot(true);
timer->start(5000);
}
void MainWindow::AddValueLCD()
{
c = c + a;
ui->lcdNumber->display(c);
}
What I want do but is :
1st
When I press two time the button 1 in this case it write on the LCD "11" and not 1.
2nd
When the timer end it add to my start number not original + 1 + 1 but original + 1.
Somebody have the possibility to help me ?
Thank s in advance.
I start to learn the QT but I have some problem with an example that I'm try to develop.
This is the part of the code
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QIntegerForSize"
#include "QTimer"
#include "QLabel"
#include "QString"
#include "mainwindow.h"
int a;
int c;
bool b;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::GreenUnoClick()
{
if (b != true)
{
a = (a*10) + 1;
}
else
{
c = ui->lcdNumber->intValue();
a = 1;
}
b = true;
ui->lcdNumber->display(a);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(AddValueLCD()));
timer->setSingleShot(true);
timer->start(5000);
}
void MainWindow::AddValueLCD()
{
c = c + a;
ui->lcdNumber->display(c);
}
What I want do but is :
1st
When I press two time the button 1 in this case it write on the LCD "11" and not 1.
2nd
When the timer end it add to my start number not original + 1 + 1 but original + 1.
Somebody have the possibility to help me ?
Thank s in advance.