This is what I wrote to make a simple timer.
openSuse 11, Qt 4.5, Qt Creator, Qt GUI App
It doesn't work, I mean when I try to execute it "Hi" doesn't appear on Konsole. I tried to debug it in the constructor of the class, but gdb never goes there.
Thanks for your help
MyObject.h
#include <QtCore/QObject>
#include <QtCore/QTimer>
{
Q_OBJECT
public:
MyObject();
private:
private slots:
void timerEvent();
};
#include <QtCore/QObject>
#include <QtCore/QTimer>
class MyObject : public QObject
{
Q_OBJECT
public:
MyObject();
private:
QTimer *timer;
private slots:
void timerEvent();
};
To copy to clipboard, switch view to plain text mode
main.cpp
MyObject::MyObject()
{
connect(timer, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer->setInterval(10);
timer->start();
}
void MyObject::timerEvent()
{
std::cout << "Hi" << std::endl;
timer->start();
}
int main()
{
MyObject mo;
sleep(5);
return 0;
}
MyObject::MyObject()
{
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer->setInterval(10);
timer->start();
}
void MyObject::timerEvent()
{
std::cout << "Hi" << std::endl;
timer->start();
}
int main()
{
MyObject mo;
sleep(5);
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks