rezas1000
18th August 2014, 12:50
Hello
The following code is correct:
#include <QtWidgets>
class DigitalClock : public QLCDNumber
{
Q_OBJECT
public:
DigitalClock(QWidget *parent = 0);
private slots:
void showTime();
};
#include <QtWidgets>
#include "u.h"
DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
setWindowTitle(tr("Digital Clock"));
resize(150, 60);
}
void DigitalClock::showTime()
{
QTime time = QTime:: currentTime();
QString text = time.toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
display(text);
}
#include <QApplication>
#include "u.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DigitalClock clock;
clock.show();
return app.exec();
}
and pro is;
QT += gui core widgets
SOURCES += \
main.cpp \
u.cpp
HEADERS += \
u.h
But when I change the colored part as follows:
Not run as before:
QTime time ; time. currentTime();
thanks
The following code is correct:
#include <QtWidgets>
class DigitalClock : public QLCDNumber
{
Q_OBJECT
public:
DigitalClock(QWidget *parent = 0);
private slots:
void showTime();
};
#include <QtWidgets>
#include "u.h"
DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
setWindowTitle(tr("Digital Clock"));
resize(150, 60);
}
void DigitalClock::showTime()
{
QTime time = QTime:: currentTime();
QString text = time.toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
display(text);
}
#include <QApplication>
#include "u.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DigitalClock clock;
clock.show();
return app.exec();
}
and pro is;
QT += gui core widgets
SOURCES += \
main.cpp \
u.cpp
HEADERS += \
u.h
But when I change the colored part as follows:
Not run as before:
QTime time ; time. currentTime();
thanks