Results 1 to 14 of 14

Thread: Display changes of integer variable to lcd number

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2013
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: Display changes of integer variable to lcd number

    Thanks for the reply..

    Could you please show a simple code example..?
    I'm still in the middle of learning the timer and process event because I never use it before..

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

    Default Re: Display changes of integer variable to lcd number

    You have never called a method on a C++ object?

    Syntax for a pointer is: objectVariable->methodName(argumentlist);

    E.g.
    Qt Code:
    1. app->processEvents();
    To copy to clipboard, switch view to plain text mode 
    or in one line
    Qt Code:
    1. QCoreApplication::instance()->processEvents();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    micmec (12th November 2013)

  4. #3
    Join Date
    Nov 2013
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: Display changes of integer variable to lcd number

    Sorry, but that's not what I meant . I mean some example of using it. Here is my code.

    Qt Code:
    1. Monitor::Monitor(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::Monitor)
    4. {
    5. ui->setupUi(this);
    6. QCoreApplication *app = QCoreApplication::instance();
    7.  
    8. this->count=0;
    9. for(int i=0;i<100;i++){
    10. this->ui->lcdNumber->display(count);
    11. for(int j=0;j<5000000;j++){
    12.  
    13. }
    14. this->count++;
    15. app->processEvents();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    The truth is I have to make a monitoring program with Qt. My code just displays 99, not 0 to 99. Or is there another way to do monitoring with Qt?
    Sorry if I'm too much asking...

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: Display changes of integer variable to lcd number

    What You are monitoring ? Using infinite loop probably is a bad design.
    Perhaps as a result of the optimization for loop is not executed because it is empty and You don't see changes of lcdNumber.

    PS
    I think I know where the problem is. Show us a main() function. I suspect that You are trying to play with GUI in constructor of main widget before start QApplication.

  6. The following user says thank you to Lesiok for this useful post:

    micmec (12th November 2013)

  7. #5
    Join Date
    Nov 2013
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5

    Default Re: Display changes of integer variable to lcd number

    This is my main function

    Qt Code:
    1. #include "monitor.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Monitor w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Sorry if it's kind of embarassing because I'm still new to this. The programming languages that I have learned are just C and Java, but I'm still just a student so I just know the basics.

  8. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Display changes of integer variable to lcd number

    If your compiler is gcc and optimization is O2 (default for qmake generated Makefiles), your empty loop is removed for sure. I don't know about other compilers.
    If you really want to see the cool effect of changing a number on lcd widget (which is apparently your only goal here), connect a timer with a non-zero timeout to a slot, in which you increment a variable by 1 and display it.

  9. The following user says thank you to stampede for this useful post:

    micmec (12th November 2013)

Similar Threads

  1. Replies: 5
    Last Post: 19th February 2013, 15:49
  2. Replies: 1
    Last Post: 5th June 2010, 21:34
  3. display number on label
    By aj2903 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2009, 07:24
  4. qmake - how to extract number from variable
    By Vanir in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2009, 18:12
  5. Display row Number in QMessageBox
    By arunvv in forum Newbie
    Replies: 6
    Last Post: 1st May 2008, 23:24

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.