Qt Forum - programming with C++ and Qt
Register Calendar Members List Team Members Search Frequently Asked Questions Go to the Main Page

Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Programming » Can we change the values in QwtThermo dynamically? » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites
Post New Thread Post Reply
Go to the bottom of this page Can we change the values in QwtThermo dynamically?
Author
Post « Previous Thread | Next Thread »
srinivasj
Coder


Registration Date: 09.05.2008
Posts: 17

Level: 5 [?]
Experience: 125
Next Level: 173

48 points of experience needed for next level

Can we change the values in QwtThermo dynamically? Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

[COLOR=darkblue]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:red face rientation 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:red face rientation 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 time(s), it was last edited by srinivasj: 09.05.2008 14:48.

09.05.2008 11:54 srinivasj is offline Send an Email to srinivasj Search for Posts by srinivasj Add srinivasj to your Buddy List
Nicolas SOUCHON
Wizard


Registration Date: 27.06.2007
Posts: 728

Level: 29 [?]
Experience: 236,167
Next Level: 242,754

6,587 points of experience needed for next level

Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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

you set values greater than 10 !!!

__________________
Nicolas
09.05.2008 18:43 Nicolas SOUCHON is online Send an Email to Nicolas SOUCHON Search for Posts by Nicolas SOUCHON Add Nicolas SOUCHON to your Buddy List
srinivasj
Coder


Registration Date: 09.05.2008
Posts: 17

Level: 5 [?]
Experience: 125
Next Level: 173

48 points of experience needed for next level

Thread Starter Thread Started by srinivasj
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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);
10.05.2008 08:53 srinivasj is offline Send an Email to srinivasj Search for Posts by srinivasj Add srinivasj to your Buddy List
Nicolas SOUCHON
Wizard


Registration Date: 27.06.2007
Posts: 728

Level: 29 [?]
Experience: 236,167
Next Level: 242,754

6,587 points of experience needed for next level

Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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)

Attachment:
unknown main.cpp (2.17 KB, 3 downloads)


__________________
Nicolas

This post has been edited 3 time(s), it was last edited by Nicolas SOUCHON: 10.05.2008 09:26.

10.05.2008 09:24 Nicolas SOUCHON is online Send an Email to Nicolas SOUCHON Search for Posts by Nicolas SOUCHON Add Nicolas SOUCHON to your Buddy List
srinivasj
Coder


Registration Date: 09.05.2008
Posts: 17

Level: 5 [?]
Experience: 125
Next Level: 173

48 points of experience needed for next level

Thread Starter Thread Started by srinivasj
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

I have done the same thing which you told, but the created thermometer is not getting attached to the time groupBox.
10.05.2008 09:48 srinivasj is offline Send an Email to srinivasj Search for Posts by srinivasj Add srinivasj to your Buddy List
srinivasj
Coder


Registration Date: 09.05.2008
Posts: 17

Level: 5 [?]
Experience: 125
Next Level: 173

48 points of experience needed for next level

Thread Starter Thread Started by srinivasj
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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

No I could see the values getting refreshed.

Thanks a lot..
10.05.2008 09:54 srinivasj is offline Send an Email to srinivasj Search for Posts by srinivasj Add srinivasj to your Buddy List
srinivasj
Coder


Registration Date: 09.05.2008
Posts: 17

Level: 5 [?]
Experience: 125
Next Level: 173

48 points of experience needed for next level

Thread Starter Thread Started by srinivasj
Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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.
10.05.2008 10:12 srinivasj is offline Send an Email to srinivasj Search for Posts by srinivasj Add srinivasj to your Buddy List
Nicolas SOUCHON
Wizard


Registration Date: 27.06.2007
Posts: 728

Level: 29 [?]
Experience: 236,167
Next Level: 242,754

6,587 points of experience needed for next level

Reply to this Post Post Reply with Quote Edit/Delete Posts Report Post to a Moderator       Go to the top of this page

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

set the start range to [0..100],
at each timerEvent
code:
1:
2:
3:
4:
5:
// pseudo code
while( val > thermo_max ) thermo_max += 100;
thermo_val = val;


__________________
Nicolas
10.05.2008 17:40 Nicolas SOUCHON is online Send an Email to Nicolas SOUCHON Search for Posts by Nicolas SOUCHON Add Nicolas SOUCHON to your Buddy List
Tree Structure | Board Structure
Jump to:
Post New Thread Post Reply
Qt Forum - programming with C++ and Qt » QtForum.org » Qt » Qt Programming » Can we change the values in QwtThermo dynamically?

views today: 10.129 | views yesterday: 17.520 | total views: 10.243.498


Klebekork Shop - Linux Shop - Kontaktanzeigen - Linux Forum -  SMS Gewinnspiel -  Hotels -  Stadtpläne -  Branchenbuch & Stadtplan

Branchenbuch Österreich - Branchenbuch Niederlande - Portugal Branchenverzeichnis - Spanien Branchenverzeichnis 
Telefonbuch - Branchenbuch Frankreich