PDA

View Full Version : Real Time Displaying



Ohmu11
17th February 2015, 19:59
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.

d_stranz
17th February 2015, 21:41
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.

Ohmu11
18th February 2015, 18:26
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


#include "dialog.h"
#include "ui_dialog.h"
#include "mcp3008Spi.h"
#include <QtCore/QString>
#include <QtGui>
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
#include <QLineEdit>
#include <QWidget>
#include <QPainter>

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{

ui->setupUi(this);
//connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(paintEvent( QPaintEvent *e)));

}
Dialog::~Dialog()
{

delete ui;
}

void Dialog::on_pushButton_clicked()
{
mcp3008Spi a2d("/dev/spidev0.0", SPI_MODE_0, 1000000, 8);

int a2dChannel = 0;
unsigned char data[3];
//int a2dplot[] = {};
i = 0;
while(i < 5)
{
data[0] = 1; // first byte transmitted -> start bit
data[1] = 0b10000000 |( ((a2dChannel & 7) << 4)); // second byte transmitted -> (SGL/DIF = 1, D2=D1=D0=0)
data[2] = 0; // third byte transmitted....don't care

a2d.spiWriteRead(data, sizeof(data) );
a2dVal = 0;
a2dVal = (data[1]<< 8) & 0b1100000000; //merge data[1] & data[2] to get result
a2dVal |= (data[2] & 0xff);


a2dplot[i] = a2dVal;

ui -> lcdNumber -> display(a2dplot[i]);

sleep(1);
i++ ;
update();
}

}

d_stranz
18th February 2015, 19:00
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).

ChrisW67
18th February 2015, 20:13
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.

lun01
8th July 2015, 17:20
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?
11261

lun01
9th July 2015, 13:02
I forgot, I'm using Qt 5.1 on a Windows 7 pro
The data is updated every 100ms
Lun01