i have a Qtablewidget in forms and i want to add data dynamically in the rows and columns.i have a timer and i am incrementing value of a variable after every 1 second. so i want that after everyone second my value should generate in table and when after 1 second my second value comes ,my first value should shift in second row and so on…
lyk this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGroupbox>
#include <QPainter>
#include <QPen>
#include <QTimer>
#include <QTime>
int r=0;
int c=0;
int b=0;
QString textstr;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
timer->start(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(time()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow :: paintEvent(QPaintEvent *)
{
QVariant v( b);
textstr=v.toString();
//QPainter p(this);
// p.drawText(10,50,textstr);
for(r=0;r<1;r++)
{
for(c=0;c<1;c++)
{
QTableWidgetItem *item = new QTableWidgetItem();
item->setText(textstr);
ui->tableWidget->setItem(r,c,item);
}
}
}
void MainWindow :: time()
{
b++;
update();
}
i want that everytime my new value comes ,a new row is created.
so please help me out by changing this code.
↧