Results 1 to 7 of 7

Thread: Real Time Displaying

  1. #1
    Join Date
    Feb 2015
    Posts
    4
    Qt products
    Platforms
    Unix/X11

    Default Real Time Displaying

    I'm using qt in my project and try to let qt working real time, but it always show only the last result. I need to do as https://www.youtube.com/watch?v=pestLMhRIWc . Can suggest me, Thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Real Time Displaying

    but it always show only the last result.
    And what does that mean? What is the "result" in this case, and how are you trying to "show" it? The video is useless in helping to answer your question - all it shows is a blinking LED.

  3. #3
    Join Date
    Feb 2015
    Posts
    4
    Qt products
    Platforms
    Unix/X11

    Default Re: Real Time Displaying

    When i run this code it's not real time on second, but in loop while complete 5 sec will show the last result. I have no idea to modify code, Thanks

    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include "mcp3008Spi.h"
    4. #include <QtCore/QString>
    5. #include <QtGui>
    6. #include <QtCore/QFile>
    7. #include <QtCore/QDebug>
    8. #include <QtCore/QTextStream>
    9. #include <QLineEdit>
    10. #include <QWidget>
    11. #include <QPainter>
    12.  
    13. Dialog::Dialog(QWidget *parent) :
    14. QDialog(parent),
    15. ui(new Ui::Dialog)
    16. {
    17.  
    18. ui->setupUi(this);
    19. //connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(paintEvent(QPaintEvent *e)));
    20.  
    21. }
    22. Dialog::~Dialog()
    23. {
    24.  
    25. delete ui;
    26. }
    27.  
    28. void Dialog::on_pushButton_clicked()
    29. {
    30. mcp3008Spi a2d("/dev/spidev0.0", SPI_MODE_0, 1000000, 8);
    31.  
    32. int a2dChannel = 0;
    33. unsigned char data[3];
    34. //int a2dplot[] = {};
    35. i = 0;
    36. while(i < 5)
    37. {
    38. data[0] = 1; // first byte transmitted -> start bit
    39. data[1] = 0b10000000 |( ((a2dChannel & 7) << 4)); // second byte transmitted -> (SGL/DIF = 1, D2=D1=D0=0)
    40. data[2] = 0; // third byte transmitted....don't care
    41.  
    42. a2d.spiWriteRead(data, sizeof(data) );
    43. a2dVal = 0;
    44. a2dVal = (data[1]<< 8) & 0b1100000000; //merge data[1] & data[2] to get result
    45. a2dVal |= (data[2] & 0xff);
    46.  
    47.  
    48. a2dplot[i] = a2dVal;
    49.  
    50. ui -> lcdNumber -> display(a2dplot[i]);
    51.  
    52. sleep(1);
    53. i++ ;
    54. update();
    55. }
    56.  
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 19th February 2015 at 09:01. Reason: changed [quote] to [code]

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Real Time Displaying

    Please use CODE tags, not QUOTE tags when posting code.

    The update() call in your pushbutton slot does nothing except put a paint event onto the event queue. It doesn't repaint anything. So your while() loop is simply running and doing nothing to change the GUI except to tell it that when control returns to the event loop, it should repaint.

    The reason you see only the last result is because when there are multiple paint events on the queue, Qt only executes the last one and deletes the rest.

    If you want to actually see the intermediate values, then you have to give Qt the ability to return to the event loop so it can process the paint events. You do that by replacing update() with QCoreApplication::processEvents() (or by implementing a better design).

  5. #5
    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: Real Time Displaying

    Have your pushbutton start a QTimer set to 1000 milliseconds. Move the code to read and display a single ADC value into a slot connected to the timer's timeout() signal. Throw away the code that loops, sleeps and tries to force an update().

    You might want to add a way to stop the QTimer. Perhaps make the start pushbutton a toggle.

  6. #6
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Real Time Displaying

    Hello,

    I'm quite new using QT creator. I'm an internship and they gave me an interface that plots accelerometer coordinates in Real-time display but the timescale goes faster than the plot.
    I tried to change TimeScaleDraw, QTimerstart and interval, Bottom AxisScale, origineTime but the time shift stills.

    Could anybody help me please?
    Attachment 11261
    Best regards,
    Lun01

  7. #7
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Real Time Displaying

    I forgot, I'm using Qt 5.1 on a Windows 7 pro
    The data is updated every 100ms
    Lun01
    Last edited by lun01; 9th July 2015 at 13:05. Reason: updated contents

Similar Threads

  1. zoomer on real time ?
    By hassinoss in forum Qwt
    Replies: 1
    Last Post: 27th January 2014, 14:46
  2. Qwt real time
    By oddytz1989 in forum Qwt
    Replies: 3
    Last Post: 10th February 2012, 04:41
  3. Zoom in real time
    By oddytz1989 in forum Qwt
    Replies: 4
    Last Post: 7th February 2012, 05:00
  4. Real time QT application?
    By marc2050 in forum Newbie
    Replies: 1
    Last Post: 8th June 2011, 06:08
  5. Displaying real time images
    By Sheetal in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2007, 11:29

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.