Okay, I finally whipped up a test app, and found some problems. Here is the working program:
#ifndef BLINKINGICON_H
#define BLINKINGICON_H
#include <QtGui>
#include <QtCore>
class BlinkingIcon
: public QWidget{
Q_OBJECT
public:
BlinkingIcon
(QWidget * parent
= 0);
virtual ~BlinkingIcon();
public slots:
void startBlinking();
private:
};
#endif // BLINKINGICON_H
#include "blinkingicon.h"
{
this->setWindowTitle(tr("My Blinking Icon"));
this->setFixedSize(50, 50);
m_display_image
= new QLabel(this);
m_display_image->setScaledContents(true);
this->startBlinking();
connect(timer, SIGNAL(timeout()), this, SLOT(startBlinking()));
timer->start(1000);
}
BlinkingIcon::~BlinkingIcon()
{}
void BlinkingIcon::startBlinking()
{
static bool on = false;
m_display_image->clear();
if (on)
{
m_display_image
->setPixmap
(QPixmap("C:/my_second_image.png"));
on = false;
}
else
{
m_display_image
->setPixmap
(QPixmap("C:/my_first_image.png"));
on = true;
}
m_display_image->resize(50, 50);
}
#ifndef BLINKINGICON_H
#define BLINKINGICON_H
#include <QtGui>
#include <QtCore>
class BlinkingIcon : public QWidget
{
Q_OBJECT
public:
BlinkingIcon(QWidget * parent = 0);
virtual ~BlinkingIcon();
public slots:
void startBlinking();
private:
QLabel * m_display_image;
};
#endif // BLINKINGICON_H
#include "blinkingicon.h"
BlinkingIcon::BlinkingIcon(QWidget * parent) : QWidget(parent)
{
this->setWindowTitle(tr("My Blinking Icon"));
this->setFixedSize(50, 50);
m_display_image = new QLabel(this);
m_display_image->setScaledContents(true);
this->startBlinking();
QTimer * timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(startBlinking()));
timer->start(1000);
}
BlinkingIcon::~BlinkingIcon()
{}
void BlinkingIcon::startBlinking()
{
static bool on = false;
m_display_image->clear();
if (on)
{
m_display_image->setPixmap(QPixmap("C:/my_second_image.png"));
on = false;
}
else
{
m_display_image->setPixmap(QPixmap("C:/my_first_image.png"));
on = true;
}
m_display_image->resize(50, 50);
}
To copy to clipboard, switch view to plain text mode
The first problem was that in your header file, you need to put your slot methods under:
public slots:
(or protected/private, depending who you want to be able to call)
After I changed that it worked fine, although sometimes the timer.second() test you were doing would not work as expected, so I changed the test to what you see now...
Bookmarks