Sunday, July 6th 2008, 10:57pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, May 9th 2008, 10:54am

Can we change the values in QwtThermo dynamically?

Using a timer event I am trying to change the values in the QWT thermo.

For every timer event I want to show different values on the thermo.

But in my case it is not happening.

Only the value at the first timer event is shown on the thermoafter that the values on QWT thermo are not getting refreshed.

Please provide me a solution to refresh the values on QwtThermo.

Code :


#include<qapplication.h>

#include <qgroupbox.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qlabel.h>
#include <iostream>
#include <qframe.h>
#include <qwt_thermo.h>
#include <sys/time.h>
#include <signal.h>

using namespace std;

class SysInfo ;
SysInfo *info;
int iteration = 10 ;
int timerId;

double sri = 10;


QLabel *d_timelabel;
QwtThermo *d_timethermo;
double delay = 1;
class ValueBar: public QWidget
{
public:
ValueBar(Qt::Orientation orientation,
const QString &text, QWidget *parent):
QWidget(parent)
{
d_timelabel = new QLabel(text, this);
d_timethermo = new QwtThermo(this);
d_timethermo->setRange(0,sri);

d_timethermo->setMargin(5);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);

d_timelabel->setAlignment(Qt::AlignRight);
d_timethermo->setOrientation(orientation, QwtThermo::LeftScale);

layout->addWidget(d_timethermo, 10, Qt::AlignHCenter);

layout->addWidget(d_timelabel, 0);

}

~ValueBar()
{

}


private:
// QwtThermo *d_thermo;
};

QGroupBox *timeBox;
QVBoxLayout *timeLayout;
Qt::Orientation o1,o2;
class SysInfo : public QFrame
{
public:
SysInfo(QWidget *parent = NULL):
QFrame(parent)
{

#if 1

o1 = Qt::Vertical;
timeBox = new QGroupBox("Time", this);

timeLayout = new QVBoxLayout(timeBox);
timeLayout->setMargin(15);
timeLayout->setSpacing(5);
d_timethermo->setFillColor(QColor("DarkMagenta"));
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(10);
layout->addWidget(timeBox, 0);

#endif

}
~SysInfo()
{

}

void timerEvent(QTimerEvent *)
{
timeLayout->addWidget(new ValueBar(o1, "Time Factor",timeBox));
d_timethermo->setValue(sri);
cout<<"srii:::::::::::" << sri <<endl;
info->show();
update();
sri = sri+10;
iteration--;
cout<<"THE NUMBER OF ITERATIONS LEFT:"<<iteration<<endl;
if(iteration == 0X0)
{
killTimer(timerId);
}

}
void closeEvent(QCloseEvent *)
{
exit(0);
}
};

int main(int argc , char **argv)
{
QApplication a( argc, argv );

SysInfo *sysinfo = new SysInfo;

sysinfo->setGeometry(705,190,320,170);
info = sysinfo;

timerId = sysinfo->startTimer(delay*1000);
return a.exec();

}





Thanks in Advance.

This post has been edited 3 times, last edit by "srinivasj" (May 9th 2008, 1:48pm)

  • Go to the top of the page

2

Friday, May 9th 2008, 5:43pm

you set the range of the thermometer [0..10]

you set values greater than 10 !!!
Nicolas
  • Go to the top of the page

3

Saturday, May 10th 2008, 7:53am

But every time the timer event is getting called , a new thermometer instance is getting created and new range is being set. U ca find it in this piece of code.

void timerEvent(QTimerEvent *)
{
timeLayout->addWidget(new ValueBar(o1, "Time Factor",timeBox));
d_timethermo->setValue(sri);
cout<<"srii:::::::::::" << sri <<endl;
info->show();
update();
sri = sri+10;
}
here I am incrementing the value of sri by 10.

this incremented value is set as range .
//
d_timethermo->setRange(0,sri);
  • Go to the top of the page

4

Saturday, May 10th 2008, 8:24am

with your code from the first post I can not see anything (segmentation fault)

because of: d_timethermo->setFillColor(QColor("DarkMagenta"));

at a time where d_timethermo has not been created

other thing: why do you need to create a new thermometer each time timerEvent is called?
I think better is to create ValueBar in SysInfo creator (see attached)
Nicolas SOUCHON has attached the following file:
  • main.cpp (2.22 kB - 4 times downloaded - Last download: May 24th 2008, 3:56am)
Nicolas

This post has been edited 3 times, last edit by "Nicolas SOUCHON" (May 10th 2008, 8:26am)

  • Go to the top of the page

5

Saturday, May 10th 2008, 8:48am

I have done the same thing which you told, but the created thermometer is not getting attached to the time groupBox.
  • Go to the top of the page

6

Saturday, May 10th 2008, 8:54am

Sorry Nicholas.. I did not verify the output correctly.

No I could see the values getting refreshed.

Thanks a lot..
  • Go to the top of the page

7

Saturday, May 10th 2008, 9:12am

I have a doubt .


In the actual actual the range of the thermo has to changed, i.e; I dont know the maximum value that has to be plotted.

the value comes from the /proc/stat file which changes dynamically basing on the load of the cpu.
  • Go to the top of the page

8

Saturday, May 10th 2008, 4:40pm

I suppose ve value to be set is in the range [0 .. nbCpu * 100]

set the start range to [0..100],
at each timerEvent

Source code

1
2
3
// pseudo code
while( val > thermo_max ) thermo_max += 100;
thermo_val = val;
Nicolas
  • Go to the top of the page

Rate this thread