There is a problem in the code
Hello
The following code is correct:
Code:
#include <QtWidgets>
{
Q_OBJECT
public:
private slots:
void showTime();
};
Code:
#include <QtWidgets>
#include "u.h"
DigitalClock
::DigitalClock(QWidget *parent
){
setSegmentStyle(Filled);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
setWindowTitle(tr("Digital Clock"));
resize(150, 60);
}
void DigitalClock::showTime()
{
[COLOR
="#FF0000"] QTime time = QTime:: currentTime();
[/COLOR
] QString text
= time.
toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
display(text);
}
Code:
#include <QApplication>
#include "u.h"
int main(int argc, char *argv[])
{
DigitalClock clock;
clock.show();
return app.exec();
}
and pro is;
Quote:
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:
Code:
QTime time ;
time.
currentTime();
thanks
Re: There is a problem in the code
The two following piece of code:
is not equivalent to:
Code:
QTime time;
time.
currentTime();
The first one assigns the return value of QTime::currentTime() to the 'time' variable, the second one doesn't assign anything anywhere resulting in the 'time' variable containing its default (invalid time) value.
Re: There is a problem in the code
Hello
If the code is correct :
digitalClock::digitalClock(QWidget *parent)
: QLCDNumber(parent) {
....
....
The following code should be correct?!!!!!!!!
class a
{public:
a(int x):int(x){}
};
Please explain
thanks.
Re: There is a problem in the code
No, why do you think it should be?
Cheers,
_
Re: There is a problem in the code
Quote:
Originally Posted by
anda_skoa
No, why do you think it should be?
Cheers,
_
Because int is a data type And QLCDNumber is data type.
for QLCDNumber,What happens in the following code?
digitalClock::digitalClock(QWidget *parent)
: QLCDNumber(parent) {
.....
.....
Re: There is a problem in the code
But digitalClock is related to QLCDNumber, it is derived from it (a subclass of QLCFNumber).
The code is calling the base class constructor with an argument provided to the subclass constructor.
There is no such relation between "a" and "int".
Cheers,
_
Re: There is a problem in the code
The following code :
Code:
#include <QtWidgets>
#include "u.h"
DigitalClock
::DigitalClock(QWidget *parent
){
setSegmentStyle(Filled);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
setWindowTitle(tr("Digital Clock"));
resize(150, 60);
}
void DigitalClock::showTime()
{
[COLOR
="#FF0000"] QTime time = QTime:: currentTime();
[/COLOR
] QString text
= time.
toString("hh:mm");
if ((time.second() % 2) == 0)
"this",where to point?
thanks.
Re: There is a problem in the code
Quote:
Originally Posted by
rezas1000
The following code :
"this",where to point?
thanks.
Where ever that is, shows himself - in this case, the object of the class DigitalClock.
Re: There is a problem in the code
It seems that you do not have basic C++ knowledge, which is required to create a more complex application than "hello world".
My advice is to start from the beginning - get the C++ book and start with the HelloWorld and then slowly get through the classes and structs to inheritance and virtual functions. Then you'll be ready to develop your Qt application, as this is the knowledge you *must* have.
For example: You can't write the book in German language if you don't know this language, right? First you have to learn German and then start writing a book.