Results 1 to 10 of 10

Thread: erro code undeclared With timer

  1. #1
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default erro code undeclared With timer

    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??

    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
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <Qtime>
    4. #include <Qtimer.h>
    5. #include <QPalette>
    6.  
    7.  
    8. MainWindow::MainWindow(QWidget *parent, Qt::WFlags f) :
    9. QMainWindow(parent, f),
    10. ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13. seconds = minutes = 0;
    14. timer = new QTimer(this);
    15. connect(timer, SIGNAL(timeout()), this, SLOT(count()));
    16. connect(btstart, SIGNAL(clicked()), this, SLOT(start()));
    17. connect(btstop, SIGNAL(clicked()), this, SLOT(stop()));
    18. connect(btreset, SIGNAL(clicked()), this, SLOT(reset()));
    19. }
    20.  
    21. void MaindWindow::count(){
    22. seconds++;
    23. if(seconds==60) {
    24. minute++;
    25. seconds=0;
    26.  
    27. }
    28. lcdSeconds->display(seconds);
    29. lcdMinutes->display(minutes);
    30. }
    31.  
    32. void MainWindow::start(){
    33. timer->start(1000);
    34. }
    35.  
    36. void MainWindow::stop(){
    37. timer->start();
    38. }
    39.  
    40. void MainWindow::reset(){
    41. seconds = minutes = 0;
    42. }
    43.  
    44. MainWindow::~MainWindow()
    45. {
    46. delete ui;
    47. }
    48.  
    49. void MainWindow::changeEvent(QEvent *e)
    50. {
    51. QMainWindow::changeEvent(e);
    52. switch (e->type()) {
    53. case QEvent::LanguageChange:
    54. ui->retranslateUi(this);
    55. break;
    56. default:
    57. break;
    58. }
    59. }
    60.  
    61. void MainWindow::on_lcdNumber_overflow()
    62. {
    63.  
    64. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QTimer>
    6. #include "ui_mainwindow.h"
    7.  
    8. namespace Ui {
    9. class MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow {
    13. Q_OBJECT
    14. public:
    15. QTimer * timer;
    16. int seconds;
    17. int minutes;
    18.  
    19. MainWindow(QWidget *parent = 0, Qt::WFlags f = 0);
    20. ~MainWindow();
    21.  
    22. protected:
    23. void changeEvent(QEvent *e);
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27.  
    28. private slots:
    29. void on_btstart_clicked();
    30. void count();
    31. void start();
    32. void stop();
    33. void reset();
    34. void on_lcdNumber_overflow();
    35. };
    36.  
    37. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 29th February 2012 at 13:46.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: erro code undeclared With timer

    So what is "btstart"? Shouldn't it be ui->btstart?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: erro code undeclared With timer

    Qt Code:
    1. void MainWindow::stop(){
    2. timer->start();
    3. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: erro code undeclared With timer

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: erro code undeclared With timer

    Come on, ui->lcdSeconds and ui->lcdMinutes?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: erro code undeclared With timer

    Quote Originally Posted by wysota View Post
    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

    Qt Code:
    1. #include "mainwindowimpl.h"
    2. //
    3. MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
    4. : QMainWindow(parent, f)
    5. {
    6. setupUi(this);
    7. seconds = minutes = 0;
    8. timer = new QTimer(this);
    9. connect(timer, SIGNAL(timeout()), this, SLOT(count()));
    10.  
    11. }
    12.  
    13. void MainWindowImpl::count(){
    14. seconds++;
    15. if(seconds == 60) {
    16. minutes++;
    17. seconds=0;
    18. }
    19. if(seconds == 100) {
    20. minutes=0;
    21. }
    22. lcdSeconds->display(seconds);
    23. lcdMinutes->display(minutes);
    24. }
    25.  
    26.  
    27.  
    28. void MainWindowImpl::on_btStart_clicked()
    29. {
    30. timer->start(1000);
    31. }
    32.  
    33. void MainWindowImpl::on_btStop_clicked()
    34. {
    35. timer->stop();
    36. }
    37.  
    38. void MainWindowImpl::on_btReset_clicked()
    39. {
    40. seconds = minutes = 0;
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 6th March 2012 at 20:17. Reason: missing [code] tags

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: erro code undeclared With timer

    You are having problems with C++, not with Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: erro code undeclared With timer

    Quote Originally Posted by wysota View Post
    You are having problems with C++, not with Qt.
    How do you mean?

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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: erro code undeclared With timer

    If you are having problems with the compiler then they are related to the language and not the framework you are using.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: erro code undeclared With timer

    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:
    Quote Originally Posted by wysota
    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?

Similar Threads

  1. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  2. hello.qt make erro!
    By soliveira in forum Newbie
    Replies: 5
    Last Post: 11th February 2010, 01:48
  3. undeclared QSslCertificate
    By labaga in forum Newbie
    Replies: 5
    Last Post: 3rd December 2008, 09:30
  4. Q_UINT32 undeclared !
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2007, 09:11
  5. undeclared method - GUI Styles
    By Amanda in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2006, 13:43

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
  •  
Qt is a trademark of The Qt Company.