Menu

Qt-digital-clock

big-bass
Attachments
qt-digital-clock.png (3911 bytes)

BaCon Qt digital clock

ported from

https://doc.qt.io/qt-5/qtwidgets-widgets-digitalclock-example.html

class reference at

https://doc.qt.io/qt-5/qlcdnumber.html

EXTRA explained porting of code to BaCon

https://sourceforge.net/p/bacon-qt5/wiki/digital-clock-explained/

'ported digitalclock.cpp  and simplified it  by bigbass
'--------------------------------------
PRAGMA INCLUDE  <QtWidgets>  <QtCore>  <QtGui> 
PRAGMA INCLUDE  <QApplication>  <QLCDNumber>  <QTime>  <QTimer> 
PRAGMA LDFLAGS  -lQt5Widgets  -lQt5Core  -lQt5Gui  -lpthread -latomic -lGLESv2
PRAGMA COMPILER g++ 
PRAGMA OPTIONS -Wno-deprecated -Wno-write-strings -Wno-pointer-arith -fPIC
OPTION PARSE FALSE

'RPI 3 and 4   preset
PRAGMA OPTIONS -I/usr/include/arm-linux-gnueabihf/qt5/ 
PRAGMA OPTIONS -I/usr/include/arm-linux-gnueabihf/qt5/QtWidgets 
PRAGMA OPTIONS -I/usr/include/arm-linux-gnueabihf/qt5/QtCore 
PRAGMA OPTIONS -I/usr/include/arm-linux-gnueabihf/qt5/QtGui


'x86_64   if you need it
'PRAGMA OPTIONS -I/usr/include/x86_64-linux-gnu/qt5/ 
'PRAGMA OPTIONS -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets 
'PRAGMA OPTIONS -I/usr/include/x86_64-linux-gnu/qt5/QtCore 
'PRAGMA OPTIONS -I/usr/include/x86_64-linux-gnu/qt5/QtGui 
'--------------------------------------


    DECLARE app TYPE QApplication*
    DECLARE clock1 TYPE QLCDNumber*
    DECLARE timer1 TYPE QTimer*


    '--- some macros to make coding easier for bacon users
    '--- Make the callback code easier to remember
    DEF FN CONNECT( widget, event,cb) = QObject::connect(widget,event,cb)
    DEF FN DISPLAY() =  app->exec()
    DEF FN SHOW( widget) = (widget)->show()
    DEF FN  PRINTOUT(x) =  qDebug()  << (x)
    DEF FN  PRINTABLE(p) =  qPrintable(p) 


'--------------------------------------
SUB showTime()
'--------------------------------------
    LOCAL time2 TYPE QTime
    LOCAL txt TYPE QString

    time2 = QTime::currentTime()
    txt = time2.toString("hh:mm")

    clock1->display(txt)
    clock1->show()
END SUB


    '---MAIN
    app = new QApplication(argc, argv)
    clock1 = new QLCDNumber()
    timer1 = new QTimer()

    '--- CONNECT( widget, event,cb) 
    CONNECT( timer1, &QTimer::timeout,showTime) 
    timer1->start(1000)

    clock1->setWindowTitle("Qt BaCon Digital Clock")
    clock1->resize(350, 100)

    DISPLAY()

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.