Menu

digital-clock-explained

big-bass

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

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

Porting to BaCon explained
we dont use the class DigitalClock
which is defined in digitalclock.h
https://code.qt.io/cgit/qt/qtbase.git/plain/examples/widgets/widgets/digitalclock/digitalclock.h?h=5.15

we will need to get the class passed to the
bacon code another way later explained
we look for what class was used

class DigitalClock : public QLCDNumber

as this line of code says "in my words"
we make a class called DigitalClock modeled after
the QLCDNumber class but nothing is set im memory yet
we just declare it. Once you get the idea here
we can reproduce the QLCDNumber class in memory later
so in short this is the "clue" we are looking for

I need the QLCDNumber class visible to bacon! how do we do that
someone else called it DigitalClock but I will name it
clock1 so everytime you see clock1 it is the (QLCDNumber class)

the first step writing the bacon code is

DECLARE clock1 TYPE QLCDNumber*

notice it is a pointer!
because this is low level code we have to connect to from
Qt c++ and will work with memory our "variable" will be in memory

step 2

clock1 = new QLCDNumber()

we make a copy of the QLCDNumber class
and put it in memory using the new command
the new command creates a pointer to the MEMORY
that contains the QLCDNumber class!
we just beat the c++ system and completely ignored
the header digitalclock.h so we will have to create
the functions or subs in the bacon code now

this sub will be called

'--------------------------------------
SUB showTime()
'--------------------------------------

we dont have a real event so we use a timeout
to trigger the event called timer1 (widget)
after 1 second runs out (event) the callback (cb) showTime
happens

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

this part of the code is tricky

clock1->display(txt)

DigitalClock has a slot called display()
but we didnt use the class DigitalClock
so the display(txt) wont work outside of the class
but we went around that doing the class in memory!
remember clock1 is our new class
and the code works now
since we are out of the class
the pointer is needed
codeclock1->
instead of a ::


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.