PDA

View Full Version : erro code undeclared With timer



arninio123
29th February 2012, 11:22
Hello

I want to make a score board white a timer but i get a error message and i dont know what i can do about it
pls can someone help me?? :D

Error Message
mainwindow.cpp:16: error: `btstart' undeclared (first use this function)
mainwindow.cpp:16: error: (Each undeclared identifier is reported only once for each function it appears in.)
mainwindow.cpp:17: error: `btstop' undeclared (first use this function)
mainwindow.cpp:18: error: `btreset' undeclared (first use this function)
mainwindow.cpp: At global scope:
mainwindow.cpp:21: error: `MaindWindow' has not been declared
mainwindow.cpp: In function `void count()':
mainwindow.cpp:22: error: `seconds' undeclared (first use this function)
mainwindow.cpp:24: error: `minute' undeclared (first use this function)
mainwindow.cpp:28: error: `lcdSeconds' undeclared (first use this function)
mainwindow.cpp:29: error: `lcdMinutes' undeclared (first use this function)
mainwindow.cpp:29: error: `minutes' undeclared (first use this function)

mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Qtime>
#include <Qtimer.h>
#include <QPalette>


MainWindow::MainWindow(QWidget *parent, Qt::WFlags f) :
QMainWindow(parent, f),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
seconds = minutes = 0;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(count()));
connect(btstart, SIGNAL(clicked()), this, SLOT(start()));
connect(btstop, SIGNAL(clicked()), this, SLOT(stop()));
connect(btreset, SIGNAL(clicked()), this, SLOT(reset()));
}

void MaindWindow::count(){
seconds++;
if(seconds==60) {
minute++;
seconds=0;

}
lcdSeconds->display(seconds);
lcdMinutes->display(minutes);
}

void MainWindow::start(){
timer->start(1000);
}

void MainWindow::stop(){
timer->start();
}

void MainWindow::reset(){
seconds = minutes = 0;
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void MainWindow::on_lcdNumber_overflow()
{

}

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include "ui_mainwindow.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
QTimer * timer;
int seconds;
int minutes;

MainWindow(QWidget *parent = 0, Qt::WFlags f = 0);
~MainWindow();

protected:
void changeEvent(QEvent *e);

private:
Ui::MainWindow *ui;

private slots:
void on_btstart_clicked();
void count();
void start();
void stop();
void reset();
void on_lcdNumber_overflow();
};

#endif // MAINWINDOW_H

wysota
29th February 2012, 13:48
So what is "btstart"? Shouldn't it be ui->btstart?

Urthas
2nd March 2012, 03:26
void MainWindow::stop(){
timer->start();
}

Note: start() stops and then restarts the timer. Did you mean to call stop() instead? Just checking.

arninio123
2nd March 2012, 08:13
hi thank you

but i have 2 errors
and that is:
mainwindow.cpp:28: error: `lcdSeconds' undeclared (first use this function)
mainwindow.cpp:29: error: `lcdMinutes' undeclared (first use this function)

can you pls help how i can fix it :s

Thank you

wysota
2nd March 2012, 11:02
Come on, ui->lcdSeconds and ui->lcdMinutes?

arninio123
6th March 2012, 16:43
Come on, ui->lcdSeconds and ui->lcdMinutes?
srry i am new to qdevelop and i don't really understand what you say :s

now i got this: but i got still the same error :s


#include "mainwindowimpl.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
seconds = minutes = 0;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(count()));

}

void MainWindowImpl::count(){
seconds++;
if(seconds == 60) {
minutes++;
seconds=0;
}
if(seconds == 100) {
minutes=0;
}
lcdSeconds->display(seconds);
lcdMinutes->display(minutes);
}



void MainWindowImpl::on_btStart_clicked()
{
timer->start(1000);
}

void MainWindowImpl::on_btStop_clicked()
{
timer->stop();
}

void MainWindowImpl::on_btReset_clicked()
{
seconds = minutes = 0;
}

wysota
6th March 2012, 20:17
You are having problems with C++, not with Qt.

arninio123
6th March 2012, 21:06
You are having problems with C++, not with Qt.

How do you mean?

I really don't see what is wrong withe it :s

wysota
6th March 2012, 21:21
If you are having problems with the compiler then they are related to the language and not the framework you are using.

ChrisW67
7th March 2012, 06:43
How do you mean?
The error messages are related to variables you are attempting to use but are defined in the scope you are trying to use them. This comment:

Come on, ui->lcdSeconds and ui->lcdMinutes?
tells you how to fix this problem. It's exactly the same problem repeated from earlier in the thread and demonstrates that you have difficulty understanding how C++ variables are declared/used and the limits of their visibility. Note that this has nothing to do with Qt itself: just you, the C++ language and compiler.

Do you know what ui is? How do you access members of the ui object? What members are there?