skimmer
13th September 2012, 10:39
Assumme I have a qapplication with a qmainwindow.
In the qmainwindow is a timer emitting the signal timeout(). This signal is connected to a slot computeAlot() which does a lot of computing.
Something like this:
main.cpp
#include <QApplication>
#include "mainWindow.h"
int main(int argc, char* argv[])
{
QApplication application(argc, argv);
MainWindow mainWindow(0);
mainWindow.show();
return application.exec();
}
mainWindow.h:
#include <QMainWindow>
#include <QTest>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget * parent = 0);
private slots:
void computeAlot();
}
mainWindow.cpp
#include "mainWindow.h"
MainWindow::MainWindow(QWidget *parent)
{
const int updateRate = 10; //ms
const Qt::ConnectionType connectionType = Qt::QueuedConnection;
QTimer timer;
connect(timer, SIGNAL(timeout()), this, SLOT(computeAlot()), connectionType);
timer.start(updateRate);
}
MainWindow::ComputeAlot()
{
const int computationTime = 500; //ms
// Should do some computions here
QTest::qSleep(computationTime);
}
If the computationTime is higher than the updateRate how often will ComputeAlot() be executed if the timer stops after 100ms? Is it executed 10 times or one time or some threshold times?
Is this behavior dependent of the connectionType?
Would there be a different behavior if the ComputeAlot() would be executed in a different thread?
And if I want the computeAlot() slot be executed as often as possible while the GUI stays responsive, how do i do that? I discovered if I set the updateRate to 0 the GUI is not nicely responsive.
Thanx
In the qmainwindow is a timer emitting the signal timeout(). This signal is connected to a slot computeAlot() which does a lot of computing.
Something like this:
main.cpp
#include <QApplication>
#include "mainWindow.h"
int main(int argc, char* argv[])
{
QApplication application(argc, argv);
MainWindow mainWindow(0);
mainWindow.show();
return application.exec();
}
mainWindow.h:
#include <QMainWindow>
#include <QTest>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget * parent = 0);
private slots:
void computeAlot();
}
mainWindow.cpp
#include "mainWindow.h"
MainWindow::MainWindow(QWidget *parent)
{
const int updateRate = 10; //ms
const Qt::ConnectionType connectionType = Qt::QueuedConnection;
QTimer timer;
connect(timer, SIGNAL(timeout()), this, SLOT(computeAlot()), connectionType);
timer.start(updateRate);
}
MainWindow::ComputeAlot()
{
const int computationTime = 500; //ms
// Should do some computions here
QTest::qSleep(computationTime);
}
If the computationTime is higher than the updateRate how often will ComputeAlot() be executed if the timer stops after 100ms? Is it executed 10 times or one time or some threshold times?
Is this behavior dependent of the connectionType?
Would there be a different behavior if the ComputeAlot() would be executed in a different thread?
And if I want the computeAlot() slot be executed as often as possible while the GUI stays responsive, how do i do that? I discovered if I set the updateRate to 0 the GUI is not nicely responsive.
Thanx