Results 1 to 3 of 3

Thread: How to display an LCD with a counter

  1. #1
    Join Date
    Oct 2015
    Posts
    35
    Thanks
    11
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to display an LCD with a counter

    Hello All,

    I'm learning Qt using C++, a beginner. Trying to create LCD that starts counting from 0(zero) after execution, I want to incorporate a stop button to stop the counting when it is pressed and also want to incorporate a slider to increase or decrease the speed of counter. I want to use programming instead of UI/drag and drop functionality. This is just a start up I haven't included stop and slider yet. Can someone please guide me through this. Please!!!. Thanks in advance.

    Code in my LCD3.h
    Qt Code:
    1. #ifndef LCD3_H
    2. #define LCD3_H
    3. #include <QApplication>
    4. #include <QLCDNumber>
    5. #include <QWidget>
    6.  
    7. class ClassA: public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. ClassA():
    13. number(0)
    14. {};
    15. ~ ClassA(){};
    16.  
    17. void mylcd(ClassA *window)
    18. {
    19. QWidget *centralWidget = new QWidget(window);
    20. LCD = new QLCDNumber(centralWidget);
    21. window ->setCentralWidget(centralWidget);
    22. window->show();
    23. LCD->display(number ++);
    24. }
    25. public slots:
    26. void setNumber()
    27. {
    28. if(number>=51)
    29. {
    30. timer->stop();
    31. }
    32. else
    33. {
    34. LCD->display(number++);
    35. }
    36. }
    37. public:
    38. QLCDNumber *LCD;
    39. int number;
    40.  
    41. };
    42.  
    43. #endif // LCD3_H
    To copy to clipboard, switch view to plain text mode 





    Code in my main.cpp file
    Qt Code:
    1. #include <QApplication>
    2. #include "LCD3.h"
    3. #include <QLCDNumber>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. ClassA *window = new Test();
    11. window->setWindowTitle(QString::fromUtf8("LCD Display"));
    12. window->resize(300,300);
    13.  
    14. ClassA win;
    15. win.mylcd(window);
    16.  
    17. return a.exec();
    18. };
    To copy to clipboard, switch view to plain text mode 


    Is there a way that we can run the program in debug mode. Executing the code line by line and see what's happening on each line.



    Here are the errors I get when I execute it.

    /Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::mylcd(ClassA*)':
    /Qt Practice/LCD3/LCD3/LCD3.h:24: error: 'class ClassA' has no member named 'setCentralWidget'
    /Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::setNumber()':
    /Qt Practice/LCD3/LCD3/LCD3.h:33: error: 'timer' was not declared in this scope
    /Qt Practice/LCD3/LCD3/main.cpp:-1: In function 'int main(int, char**)':
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: expected type-specifier before 'Test'
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: cannot convert 'int*' to 'ClassA*' in initialization
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: expected ',' or ';' before 'Test'
    Last edited by anda_skoa; 24th October 2015 at 09:32. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2012
    Location
    Warsaw, Poland
    Posts
    37
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to display an LCD with a counter

    Please
    Qt Code:
    1. write code like this text
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to display an LCD with a counter

    Quote Originally Posted by rookee View Post
    /Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::mylcd(ClassA*)':
    /Qt Practice/LCD3/LCD3/LCD3.h:24: error: 'class ClassA' has no member named 'setCentralWidget'
    That means your class "ClassA" does not have a method called "setCentralWidget".
    It indeed doesn't but you try to use it.

    Quote Originally Posted by rookee View Post
    /Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::setNumber()':
    /Qt Practice/LCD3/LCD3/LCD3.h:33: error: 'timer' was not declared in this scope
    This means your class "ClassA" does not have a member variable called "timer".
    It indeed doesn't but you try to use it.

    Quote Originally Posted by rookee View Post
    /Qt Practice/LCD3/LCD3/main.cpp:-1: In function 'int main(int, char**)':
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: expected type-specifier before 'Test'
    Means the type "Test" is not know.
    Indeed you don't have such a class, your class is called "ClassA"

    Quote Originally Posted by rookee View Post
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: cannot convert 'int*' to 'ClassA*' in initialization
    /Qt Practice/LCD3/LCD3/main.cpp:10: error: expected ',' or ';' before 'Test'
    These are just follow-up errors because of the one before, they will go away once you fixed the other one.

    Cheers,
    _

Similar Threads

  1. Qt Creator Line counter plug-in
    By RolandHughes in forum Qt Tools
    Replies: 0
    Last Post: 5th June 2013, 13:36
  2. Hi Help me! Rev Counter developed
    By toro.86 in forum Jobs
    Replies: 2
    Last Post: 12th October 2010, 21:19
  3. Autoincrement builds counter
    By iddqd in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2010, 18:45
  4. Counter widget
    By eu.x in forum Newbie
    Replies: 7
    Last Post: 27th February 2007, 20:30
  5. QTableView without the first counter column?
    By pmaktieh.sirhc in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2007, 22:03

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.