jhearon
6th November 2008, 15:33
I'm trying to continuously update a widget to show numbers h:m:s:ms which are returned from a method in another api linked to Qt. That api generally uses a control loop for the method which returns the time elapsed since a method was started. I finally got QLabel to update using my own signal, and repaint, but the time displayed is very slow; much slower than realtime. The float value for the elapsed time looks fine when shown in the console.
Is there a better way to go about this to get an h:m:s:ms display which receives values from another api's method, or is it possible to display updated text in Qt without using a widget? I'm not sure what is causing the slow down.
//myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QWidget>
#include "API.hpp"
class QLabel;
class myClass : public QWidget
Q_OBJECT
public:
QLabel *mylabel;
double timeVal;
int runapi();
public slots:
void setNum (double num);
signals:
void mySignal(double newnum);
private:
API *myapi;
-----
//myclass.cpp
#include "myclass.h"
myClass::myClass()
{
myapi = new API;
mylabel = new QLabel;
connect (this, SIGNAL ( mySignal(double) ), mylabel, SLOT ( setNum(double) ) );
}
int myClass::runapi()
{
while ( myapi->myintreturn() ==0 )
{
timeVal->myapi->mymethodelapsedtime(); //returns double
mylabel->setNum(timeVal);
mylabel->repaint();
}
}
void myClass::setNum (double num)
{
emit mySignal(num);
}
Is there a better way to go about this to get an h:m:s:ms display which receives values from another api's method, or is it possible to display updated text in Qt without using a widget? I'm not sure what is causing the slow down.
//myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QWidget>
#include "API.hpp"
class QLabel;
class myClass : public QWidget
Q_OBJECT
public:
QLabel *mylabel;
double timeVal;
int runapi();
public slots:
void setNum (double num);
signals:
void mySignal(double newnum);
private:
API *myapi;
-----
//myclass.cpp
#include "myclass.h"
myClass::myClass()
{
myapi = new API;
mylabel = new QLabel;
connect (this, SIGNAL ( mySignal(double) ), mylabel, SLOT ( setNum(double) ) );
}
int myClass::runapi()
{
while ( myapi->myintreturn() ==0 )
{
timeVal->myapi->mymethodelapsedtime(); //returns double
mylabel->setNum(timeVal);
mylabel->repaint();
}
}
void myClass::setNum (double num)
{
emit mySignal(num);
}