PDA

View Full Version : Problem with view on LCDNumber



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.

Danny Fan
13th March 2011, 09:31
The thing was easy but I see only today

If somebody was interested


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QIntegerForSize"
#include "QTimer"
#include "QLabel"
#include "QString"
#include "mainwindow.h"


int a;
int c;
bool b;
char Sa;
int TimWai=2000;

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;
}
Sa = a;

ui->lcdNumber->display(a);
if (b == false)
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(AddValueLCD()));
timer->setSingleShot(true);
timer->start(TimWai);
}
b = true;

}