rookee
22nd October 2015, 19:52
Hello All,
I'm learning Qt using C++, a beginner. Trying to create LCD that starts counting from 0(zero) after execution, I want to incorporate a stop button to stop the counting when it is pressed and also want to incorporate a slider to increase or decrease the speed of counter. I want to use programming instead of UI/drag and drop functionality. This is just a start up I haven't included stop and slider yet. Can someone please guide me through this. Please!!!. Thanks in advance.
Code in my LCD3.h
#ifndef LCD3_H
#define LCD3_H
#include <QApplication>
#include <QLCDNumber>
#include <QWidget>
class ClassA: public QWidget
{
Q_OBJECT
public:
ClassA():
number(0)
{};
~ ClassA(){};
void mylcd(ClassA *window)
{
QWidget *centralWidget = new QWidget(window);
LCD = new QLCDNumber(centralWidget);
window ->setCentralWidget(centralWidget);
window->show();
LCD->display(number ++);
}
public slots:
void setNumber()
{
if(number>=51)
{
timer->stop();
}
else
{
LCD->display(number++);
}
}
public:
QLCDNumber *LCD;
int number;
};
#endif // LCD3_H
Code in my main.cpp file
#include <QApplication>
#include "LCD3.h"
#include <QLCDNumber>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ClassA *window = new Test();
window->setWindowTitle(QString::fromUtf8("LCD Display"));
window->resize(300,300);
ClassA win;
win.mylcd(window);
return a.exec();
};
Is there a way that we can run the program in debug mode. Executing the code line by line and see what's happening on each line.
Here are the errors I get when I execute it.
/Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::mylcd(ClassA*)':
/Qt Practice/LCD3/LCD3/LCD3.h:24: error: 'class ClassA' has no member named 'setCentralWidget'
/Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::setNumber()':
/Qt Practice/LCD3/LCD3/LCD3.h:33: error: 'timer' was not declared in this scope
/Qt Practice/LCD3/LCD3/main.cpp:-1: In function 'int main(int, char**)':
/Qt Practice/LCD3/LCD3/main.cpp:10: error: expected type-specifier before 'Test'
/Qt Practice/LCD3/LCD3/main.cpp:10: error: cannot convert 'int*' to 'ClassA*' in initialization
/Qt Practice/LCD3/LCD3/main.cpp:10: error: expected ',' or ';' before 'Test'
I'm learning Qt using C++, a beginner. Trying to create LCD that starts counting from 0(zero) after execution, I want to incorporate a stop button to stop the counting when it is pressed and also want to incorporate a slider to increase or decrease the speed of counter. I want to use programming instead of UI/drag and drop functionality. This is just a start up I haven't included stop and slider yet. Can someone please guide me through this. Please!!!. Thanks in advance.
Code in my LCD3.h
#ifndef LCD3_H
#define LCD3_H
#include <QApplication>
#include <QLCDNumber>
#include <QWidget>
class ClassA: public QWidget
{
Q_OBJECT
public:
ClassA():
number(0)
{};
~ ClassA(){};
void mylcd(ClassA *window)
{
QWidget *centralWidget = new QWidget(window);
LCD = new QLCDNumber(centralWidget);
window ->setCentralWidget(centralWidget);
window->show();
LCD->display(number ++);
}
public slots:
void setNumber()
{
if(number>=51)
{
timer->stop();
}
else
{
LCD->display(number++);
}
}
public:
QLCDNumber *LCD;
int number;
};
#endif // LCD3_H
Code in my main.cpp file
#include <QApplication>
#include "LCD3.h"
#include <QLCDNumber>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ClassA *window = new Test();
window->setWindowTitle(QString::fromUtf8("LCD Display"));
window->resize(300,300);
ClassA win;
win.mylcd(window);
return a.exec();
};
Is there a way that we can run the program in debug mode. Executing the code line by line and see what's happening on each line.
Here are the errors I get when I execute it.
/Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::mylcd(ClassA*)':
/Qt Practice/LCD3/LCD3/LCD3.h:24: error: 'class ClassA' has no member named 'setCentralWidget'
/Qt Practice/LCD3/LCD3/LCD3.h:-1: In member function 'void ClassA::setNumber()':
/Qt Practice/LCD3/LCD3/LCD3.h:33: error: 'timer' was not declared in this scope
/Qt Practice/LCD3/LCD3/main.cpp:-1: In function 'int main(int, char**)':
/Qt Practice/LCD3/LCD3/main.cpp:10: error: expected type-specifier before 'Test'
/Qt Practice/LCD3/LCD3/main.cpp:10: error: cannot convert 'int*' to 'ClassA*' in initialization
/Qt Practice/LCD3/LCD3/main.cpp:10: error: expected ',' or ';' before 'Test'