QT Multithread application crashing when I try to start threads - c++

I am having issues when I try to create an application that simulates a restaurant. It needs to have 50 clients, 3 cooks, 1 waiter and 30 tables. When I try to start the threads of the clients, cooks and waiter it crashes and doesnt let me do anything, nor it gives me an error message or warning. I really don't know what to do. I hope you guys can help me with the answer.
Cook class.h:
`
#ifndef COOK_H
#define COOK_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Cook : public QThread
{
Q_OBJECT
public:
Cook(int id, QString name);
void makeFood(int queueTotal);
void startCook();
private:
int id;
QString name;
int orderId;
QSemaphore semaphore;
protected:
void run(); //makeFood
};
#endif // COOK_H
cook.cpp
#include "cook.h"
#include <QTextStream>
Cook::Cook(int id, QString name)
{
this->id = id;
this->name = name;
}
void Cook::startCook(){
run();
}
void Cook::run(){
QTextStream(stdout)<< "hello im a cook";
}
`
client.h
`
#ifndef CLIENT_H
#define CLIENT_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Order;
class Client : public QThread
{
Q_OBJECT
public:
Client(int id, QString name);
void setOrder(Order* order);
int getId();
void startClient();
private:
int id;
QString name;
QSemaphore semaphore;
Order* order;
protected:
void run();
};
#endif // CLIENT_H
`
client.cpp
`
#include "client.h"
#include <QTextStream>
Client::Client(int id, QString name)
{
this->id = id;
this->name = name;
}
void Client::startClient(){
run();
}
void Client::run(){
QTextStream(stdout)<< "hello im a client";
}
void Client::setOrder(Order* order){
this->order = order;
}
int Client::getId(){
return this->id;
}
`
order.cpp and .h
`
#ifndef ORDER_H
#define ORDER_H
class Order
{
public:
Order(int orderId, bool orderType);
private:
int orderId;
bool orderType; //true carne - false vegano
};
#endif // ORDER_H
`
order.cpp
`
#include "order.h"
Order::Order(int orderId, bool orderType)
{
this->orderId = orderId;
this->orderType = orderType;
}
table.h and cpp
#ifndef TABLE_H
#define TABLE_H
#include <QObject>
class Client;
class Table
{
public:
Table(int id, QString name, bool seat);
void clearClient();
void setClient(Client newClient);
private:
int id;
QString name;
bool seat;
int clientId;
};
#endif // TABLE_H
table.cpp
#include "table.h"
#include "client.h"
Table::Table(int id, QString name, bool seat)
{
this->seat = seat;
this->clientId = 0;
this->id = id;
this->name = name;
}
void Table::clearClient(){
this->seat = false;
this->clientId = -1;
}
void Table::setClient(Client newClient){
this->clientId = newClient.getId();
this->seat = true;
}
`
waiter.h
`
#ifndef WAITER_H
#define WAITER_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Waiter : public QThread
{
Q_OBJECT
public:
Waiter(int id, QString name);
void startWaiter();
private:
int id;
QString name;
int orderId;
int tableId;
QSemaphore semaphore;
protected:
void run();
};
#endif // WAITER_H
`
waiter.cpp
`
#include "waiter.h"
#include <QTextStream>
Waiter::Waiter(int id, QString name)
{
this->id = id;
this->name = name;
}
void Waiter::startWaiter(){
run();
}
void Waiter::run(){
QTextStream(stdout)<< "hello im a waiter";
}
`
restaurant.h
`
#ifndef RESTAURANT_H
#define RESTAURANT_H
class Restaurant
{
public:
Restaurant();
void startRestaurant(int totalChefs, int totalTables, int totalWaiters, int totalClients);
};
#endif // RESTAURANT_H
`
restaurant.cpp
`
#include "restaurant.h"
#include <QThread>
#include "cook.h"
#include "client.h"
#include "waiter.h"
#include "table.h"
Restaurant::Restaurant()
{
}
void Restaurant::startRestaurant(int totalChefs, int totalTables, int totalWaiters, int totalClients){
QList <Cook*> cookList;
QList <Waiter*> waiterList;
QList <Client*> clientList;
QList <Table*> tables;
//start
for(int i=0; i<totalChefs; i++){
QString output = QStringLiteral("Cook %1").arg(i);
Cook cook(i, output);
cookList.append(&cook);
}
for(int i=0; i<totalWaiters; i++){
QString output = QStringLiteral("Waiter %1").arg(i);
Waiter waiter(i, output);
waiterList.append(&waiter);
}
for(int i=0; i<totalClients; i++){
QString output = QStringLiteral("Client %1").arg(i);
Client client(i, output);
clientList.append(&client);
}
for(int i=0; i<totalTables; i++){
QString output = QStringLiteral("Table %1").arg(i);
Table table(i, output, false);
tables.append(&table);
}
cookList.value(1)->startCook();
waiterList.value(1)->startWaiter();
clientList.value(1)->startClient();
}
`
I am new to QT so please bear that in mind, I hope you guys can help me!

Related

'Mainmenu' does not name a type

I'm working on car sharing project. So, I've done login and registration, after login the main menu is opening. In main menu I need to output a balance of an account. I do like this:
mainwindow.h
#include <QMainWindow>
#include <QMessageBox>
#include <string>
#include <QDebug>
#include "mainmenu.h"
using namespace std;
class RegData;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
RegData& givedata(); // the object of class from which I will get balance and output it in main menu
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_button_reg_clicked();
void on_button_log_clicked();
private:
Ui::MainWindow *ui;
Mainmenu *second; // the error is in this line
};
class RegData
{
private:
QString login;
QString email;
QString password;
int balance;
public:
RegData(QString log = "", QString mail = "", QString pass = "", int bal=0) : login(log), email(mail), password(pass), balance(bal)
{
}
void output()
{
qDebug() << login<<email<<password<<balance;
}
QString getLogin()
{
return login;
}
QString getEmail()
{
return email;
}
QString getPassword()
{
return password;
}
int getBalance()
{
return balance;
}
void setLogin(QString log)
{
login = log;
}
void setEmail(QString mail)
{
email = mail;
}
void setPassword(QString pass)
{
password = pass;
}
void setBalance(int balanc)
{
balance = balanc;
}
};
Ok, how I did registration:
Receiving data from file into QVector data;
Receiving data from login/pass lines etc.
If login hasn't registered yet, put the data into file
So, there are a part of code in login system. The part checks is account registered, if it is, do something. In my case I change 'givedata()' values
for(QVector<RegData>::iterator it = data.begin(); it<data.end(); it++)
{
if(loginline == it->getLogin() && passwordline == it->getPassword() || loginline == it->getEmail() && passwordline == it->getPassword())
{
islog = true;
givedata().setLogin(loginline);
givedata().setEmail(it->getEmail());
givedata().setPassword(passwordline);
givedata().setBalance(it->getBalance());
break;
}
else
{
islog = false;
}
}
but I have an error
C:\Users\david\Documents\Carsharring_files\mainwindow.h:33: ошибка: 'Mainmenu' does not name a type
Mainmenu *second;
^
What is the line for? This is for main menu window object
I need to do some things with 'givedata()' in another window, there is why I do it
mainmenu.h is included
#ifndef MAINMENU_H
#define MAINMENU_H
#include <QDialog>
#include <QMessageBox>
#include "addmoney.h"
#include "mainwindow.h"
namespace Ui {
class Mainmenu;
}
class Mainmenu : public QDialog
{
Q_OBJECT
public:
explicit Mainmenu(QWidget *parent = 0);
~Mainmenu();
private slots:
void on_plus_clicked();
private:
Ui::Mainmenu *ui;
};
#endif // MAINMENU_H
I changed nothing in mainmenu.h, but includes
You have a cyclic dependency of header files.
mainmenu,h includes mainwindow.h
mainwindow.h includes mainmenu.h
That's trouble (and note that couldn't be determined without seeing both header files).

I am getting an error on Qt, and can't figure out where I went wrong

So, I am learning my way around Q_PROPERTY, QMetaObject and QMetaProperty.
I have built a working GUI, but whenever I run the script, I get an error
Can anyone tell me what I did wrong/am doing wrong?
The QDout() function, as mentioned, is only there to display something if I successfully connected the 'Print' Button with the QDout() function.
Below I have my files that associate with the Qt Project I am working on.
This is nothing serious, only for me to learn how to do it.
qt.core.qobject.connect: QObject::connect: No such slot FileInput::writeToFile()
My Header Files:
fileinput.h
#ifndef FILEINPUT_H
#define FILEINPUT_H
#include <QWidget>
#include <QPushButton>
#include "person.h"
class FileInput : public QWidget
{
Q_OBJECT
public:
FileInput(QWidget *parent = nullptr);
void set_GUI();
public slots:
void writeToFile(QObject *obj);
void QDout(); //just a test function to test my 'connect' part
private:
QPushButton *xx;
QPushButton *pp;
};
#endif // FILEINPUT_H
person.h
#ifndef PERSON_H
#define PERSON_H
#include <QObject>
#include <QDate>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(QDate birth READ getBirth WRITE setBirth)
public:
Person();
Person(QString n, QDate d);
QString getName() const;
QDate getBirth() const;
void setName(QString n);
void setBirth(QDate d);
private:
QString name;
QDate birthDate;
};
class Product : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(double price READ getPrice WRITE setPrice)
public:
Product();
Product(QString n, double d);
QString getName() const;
double getPrice() const;
void setName(QString n);
void setPrice(double d);
private:
QString name;
double price;
};
#endif // PERSON_H
And then i have 3 .cpp files
filminput.cpp
#include "fileinput.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QMetaObject>
#include <QMetaProperty>
#include <QFile>
#include <QTextStream>
FileInput::FileInput(QWidget *parent)
: QWidget(parent)
{
}
void FileInput::set_GUI()
{
QWidget *w = new QWidget;
w->resize(250,250);
w->setWindowTitle("Q Meta Nonsence");
Product lem = Product();
lem.setName("PHIL");
lem.setPrice(16.45);
xx = new QPushButton("Exit");
pp = new QPushButton("Print");
QVBoxLayout *ll = new QVBoxLayout;
ll->addWidget(xx);
ll->addWidget(pp);
ll->setSpacing(25);
w->setLayout(ll);
w->show();
connect(xx,SIGNAL(clicked()),w,SLOT(close()));
connect(pp,SIGNAL(clicked()),this,SLOT(writeToFile(lem)));
}
void FileInput::QDout() //just prints 'success' when pressing the 'print' button
{
qDebug() << "success";
}
//this next function is supposed to write to the data.txt file
void FileInput::writeToFile(QObject *obj)
{
QFile file("C:/Users/marti/Documents/Qt/QM/data.txt");
if(!file.open(QFile::WriteOnly|QFile::Text|QFile::Append))
{
qDebug() << "Already open or there is another issue";
file.close();
}
QTextStream toFile(&file);
const QMetaObject *mo = obj->metaObject();
for(int i=mo->propertyOffset(); i<mo->propertyCount(); i++)
{
const QMetaProperty prop = mo->property(i);
QString name = prop.name();
QVariant value = prop.read(obj);
QString valStr = value.toString();
toFile << name << ": " << valStr << "\n";
}
file.close();
}
person.cpp
#include "person.h"
Person::Person()
{
name = QString();
birthDate = QDate();
}
Person::Person(QString n, QDate d)
{
name = n;
birthDate = d;
}
QString Person::getName() const
{
return name;
}
QDate Person::getBirth() const
{
return birthDate;
}
void Person::setName(QString n)
{
name = n;
}
void Person::setBirth(QDate d)
{
birthDate = d;
}
Product::Product()
{
name = QString();
price = 0.0;
}
Product::Product(QString n, double d)
{
name = n;
price = d;
}
QString Product::getName() const
{
return name;
}
double Product::getPrice() const
{
return price;
}
void Product::setName(QString n)
{
name = n;
}
void Product::setPrice(double d)
{
price = d;
}
main.cpp
#include "fileinput.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FileInput w;
w.set_GUI();
return a.exec();
}
You're using the older connect syntax which masks the problem that you're connecting a signal with no parameters to a slot that wants a parameter. To fix it use the new syntax and use a lambda to provide the extra parameter.
connect(pp, &QPushButton::clicked, this, [=](){ writeToFile(lem); });

Value lost after 2nd call of method

I have a problem with this situation (underneath) in the console.
The data is lost after passing twice in my method called in main.ccp after making the MyClass object.
main.ccp
#include <QCoreApplication>
#include <QDebug>
#include <iostream>
#include <myclass.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyClass* myClass = new MyClass();
qDebug() << "Debug part 1";
myClass->method();
qDebug() << "Debug part 2";
myClass->method();
return a.exec();
}
The result in console:
Debug part 1
0
1 ".." "0 Bytes" "26.03.2022 08:21:13"
2 "stephane/" "0 Bytes" "26.04.2022 19:48:04"
3 ".localized" "0 Bytes" "26.03.2022 08:21:13"
4 "Shared/" "0 Bytes" "26.03.2022 08:21:13"
Debug part 2
0
The sources files:
myclass.h
myclass.ccp
entrys.h
entrys.ccp
entry.h
entry.ccp
myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QObject>
#include <QString>
#include <QDateTime>
#include "entrys.h"
class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = nullptr);
void method();
signals:
private:
Entrys* entrys;
};
#endif // MYCLASS_H
myclass.ccp
#include "myclass.h"
#include <iostream>
#include "myclass.h"
#include "entry.h"
#include "entrys.h"
MyClass::MyClass(QObject *parent) : QObject(parent) {
this->entrys = new Entrys();
try {
this->entrys->setDir("/Users/","L");
} catch(ErrDirNotFound &e) {
qDebug() << e.description << " " << e.what();
}
}
void MyClass::method() {
int i = 0;
qDebug() << i;
foreach(Entry *v, this->entrys->getEntrys("L")) {
i++;
qDebug() << i << v->getName() << " " << v->getSizeString(2) << " " << v->getDateLastChangeString();
}
}
entrys.h
#ifndef ENTRYS_H
#define ENTRYS_H
#include <QObject>
#include "entry.h"
struct ErrDirNotFound: public std::exception {
QString description;
const char *what() const throw() {
return "Directory not found";
}
};
class Entrys : public QObject
{
Q_OBJECT
public:
explicit Entrys(QObject *parent = nullptr);
void setDir(QString dir, QString side);
QVector<Entry*> getEntrys(QString side);
Entry* getEntry(QString side, QString key);
QString getPath(QString side);
protected:
signals:
private:
QHash<QString, QString> hash_path;
QHash<QString, QVector<Entry*>> hash_side_entry;
void setList(QString side);
};
#endif // ENTRYS_H
entrys.ccp
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <QDebug>
#include <iostream>
#include <QDateTime>
#include <QProcess>
#include "entry.h"
#include "entrys.h"
Entrys::Entrys(QObject *parent)
: QObject{parent}
{
}
void Entrys::setList(QString side) {
QVector<Entry*> vec_entry;
QString path = this->getPath(side);
QByteArray path_ba = path.toLocal8Bit();
const char* path_cstr = path_ba.constData();
struct dirent *lecture;
DIR *dir;
struct stat buf;
QString currentPath;
int row = 0;
dir = opendir(path_cstr);
if (dir == NULL) {
ErrDirNotFound e;
QString description = "Path " + path + " don't exist !";
e.description = description;
throw e;
}
while ((lecture = readdir(dir)) != NULL) {
if (strcmp(lecture->d_name, ".") != 0) {
currentPath = path + lecture->d_name;
QByteArray path_qb = currentPath.toLocal8Bit();
const char *charCurrentPath = path_qb.constData();
if ((stat(charCurrentPath, &buf)) == -1) {
qCritical() << "stat" << currentPath;
}
int size = buf.st_size;
QDateTime modif = QDateTime::fromSecsSinceEpoch(buf.st_mtime);
Entry *entry = new Entry();
if (!strcmp(lecture->d_name, "..")) {
if (this->getPath(side) != "/") {
entry->setValue(lecture->d_name, 0, modif, 0);
}
} else {
if (S_ISDIR(buf.st_mode)) {
QString qstringTemp = lecture->d_name;
qstringTemp += "/";
entry->setValue(qstringTemp, 0, modif, buf.st_mode);
} else {
entry->setValue(lecture->d_name, size, modif, buf.st_mode);
}
}
vec_entry.append(entry);
row++;
}
}
delete lecture;
closedir(dir);
this->hash_side_entry.insert(side, vec_entry);
}
void Entrys::setDir(QString dir, QString side) {
this->hash_path.insert(side, dir);
this->setList(side);
}
QVector<Entry*> Entrys::getEntrys(QString side) {
return this->hash_side_entry.take(side);
}
QString Entrys::getPath(QString side) {
return this->hash_path[side];
}
Entry* Entrys::getEntry(QString side, QString key) {
QVector<Entry*> entry = this->getEntrys(side);
for (int i = 0; i < entry.length(); i++) {
if (entry[i]->getName() == key) {
return entry[i];
}
}
return nullptr;
}
entry.h
#ifndef ENTRY_H
#define ENTRY_H
#include <QObject>
#include <QString>
#include <QDateTime>
class Entry : public QObject
{
Q_OBJECT
public:
explicit Entry(QObject *parent = nullptr);
Entry(QString name, int size_file, QDateTime date_last_change, mode_t mode);
void setValue(QString name, int size_file, QDateTime date_last_change, mode_t mode);
QString getName();
QString getSizeString(int decimals);
QString getDateLastChangeString();
signals:
private:
QString name;
int size_file;
QDateTime date_last_change;
mode_t mode;
};
#endif // ENTRY_H
entry.ccp
#include <QDateTime>
#include "entry.h"
Entry::Entry(QObject *parent)
: QObject{parent}
{
}
Entry::Entry(QString name, int size_file, QDateTime date_last_change, mode_t mode)
{
this->name = name;
this->size_file = size_file;
this->date_last_change = date_last_change;
this->mode = mode;
}
void Entry::setValue(QString name, int size_file, QDateTime date_last_change, mode_t mode)
{
this->name = name;
this->size_file = size_file;
this->date_last_change = date_last_change;
this->mode = mode;
}
QString Entry::getName()
{
return this->name;
}
QString Entry::getSizeString(int decimals) {
int bytes = this->size_file;
if (bytes == 0) return "0 Bytes";
const int K = 1024;
const QStringList SIZES = { "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
const int I = std::floor((std::log(bytes) / std::log(K)));
int dm = decimals < 0 ? 0 : decimals;
if (I == 0) dm = 0;
return QString::number((bytes / std::pow(K, I)),'f', dm) + " " + SIZES[I];
}
QString Entry::getDateLastChangeString() {
return this->date_last_change.toString("dd.MM.yyyy hh:mm:ss");
}
Tracking through your code by eye, I find this concerning:
QVector<Entry*> Entrys::getEntrys(QString side) {
return this->hash_side_entry.take(side);
}
A bit of googling indicates that QHash's take "Removes the item with the key from the hash and returns the value associated with it." So your getEntrys is modifying your hash_side_entry - taking data out of it. Thus when your second call to method ends up calling getEntrys a second time, there's nothing in hash_side_entry anymore.

QObject::connect: No such signal progressbarV::keyReleaseEvent()

I am trying to create a project in which I have a progressbarV class which creates a QProgressBar. I am calling this class in my mainWindow. My aim is to navigate to another screen when I click on the progressbar. I tried to implement KeyRleaseEvent for this purpose, but no matter what I do, I keep getting the error "QObject::connect: No such signal progressbarV::keyReleaseEvent()". I would much appreciate any help I could get to resolve this issue.
Please find my code below:-
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include <QProgressBar>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QtWidgets>
#include <QProcess>
#include "headerfiles/progressbarV.h"
#include "headerfiles/redzonesettingsscreen.h"
class progressbarH;
class redZoneSettingsScreen;
class MainWindow : public QMainWindow//,public QProcess
{
Q_OBJECT
private:
progressbarV *progressbar_V_left;
public:
MainWindow();
~MainWindow();
void GetObjects(redZoneSettingsScreen *);
private slots:
void handleSettingsButtonPressed();
/*protected:
virtual void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;*/
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "headerfiles/mainwindow.h"
redZoneSettingsScreen *gotoSettingsScreen;
MainWindow::MainWindow()
{
progressbar_V_left = new progressbarV;
progressbar_V_left->setParent(this);
progressbar_V_left->setGeometry(350,200,90,450);
progressbar_V_left->setTitle("Height");
progressbar_V_left->setData(labelCurHeight->getDataValue());
progressbar_V_left->setMinVal(0);
progressbar_V_left->setMaxVal(labelMaxHeight->getDataValue());
connect(progressbar_V_left, SIGNAL (keyReleaseEvent()), this, SLOT
(handleSettingsButtonPressed()));
}
MainWindow::~MainWindow()
{
delete progressbar_V_left;
}
void MainWindow::GetObjects(redZoneSettingsScreen *button)
{
gotoSettingsScreen = button;
}
void MainWindow::handleSettingsButtonPressed()
{
gotoSettingsScreen->hide();
gotoSettingsScreen->show();
this->hide();
}
/*void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
}*/
progressbarV.h
#ifndef PROGRESSBARV_H
#define PROGRESSBARV_H
#include <QWidget>
#include <QProgressBar>
#include <QLabel>
#include <QPixmap>
class progressbarV: public QWidget
{
Q_OBJECT
private:
QProgressBar *progressbar_V;
QLabel *labelRedDanger, *labelYellowWarning;
float maxScaledHeight, redZoneScaledHeight, yellowZoneScaledHeight;
int spn, spn_value;
QString title;
int data;
short minVal;
short maxVal;
public:
progressbarV();
~progressbarV();
void setSPN(int);
int getSPN();
void setSPN_Value(int);
int getSPN_Value();
void setTitle(QString);
QString getTitle();
void setData(int);
int getData();
void setMinVal(short);
short getMinVal();
void setMaxVal(short);
short getMaxVal();
/*void setLowError(short);
short getLowError();
void setLowWarning(short);
short getLowWarning();
void setHighError(short);
short getHighError();
void setHighWarning(short);
short getHighWarning();*/
QProgressBar* getProgressBarV();
protected:
void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;
};
#endif // PROGRESSBARH_H
progressbarV.cpp
#include "headerfiles/progressbarV.h"
progressbarV::progressbarV()
{
progressbar_V = new QProgressBar;
progressbar_V->setParent(this);
progressbar_V->setStyleSheet("QProgressBar{ border: solid grey; border-
width: 6; border-radius: 12; text-align: center;},
QProgressBar::chunk{background-color: limegreen; width: 0px; margin:
0px;}");
progressbar_V->setGeometry(2,0,50,200);
progressbar_V->setOrientation(Qt::Vertical);
maxScaledHeight = (200*100)/120;
redZoneScaledHeight = 200 - ((maxScaledHeight*105)/100);
yellowZoneScaledHeight = 200 - ((maxScaledHeight*90)/100);
QPixmap mypixRed(":/images/images/redZone.png");
labelRedDanger = new QLabel;
labelRedDanger->setParent(this);
labelRedDanger->setGeometry(8,redZoneScaledHeight,38,3);
labelRedDanger->setPixmap(mypixRed);
QPixmap mypixYellow(":/images/images/yellowZone.png");
labelYellowWarning = new QLabel;
labelYellowWarning->setParent(this);
labelYellowWarning->setGeometry(8,yellowZoneScaledHeight,38,3);
labelYellowWarning->setPixmap(mypixYellow);
}
progressbarV::~progressbarV()
{
delete progressbar_V;
delete labelRedDanger;
delete labelYellowWarning;
}
void progressbarV::setSPN(int val)
{
spn = val;
}
int progressbarV::getSPN()
{
return spn;
}
void progressbarV::setSPN_Value(int val)
{
spn_value = val;
}
int progressbarV::getSPN_Value()
{
return spn_value;
}
void progressbarV::setTitle(QString mTitle)
{
title = mTitle;
}
QString progressbarV::getTitle()
{
return title;
}
void progressbarV::setData(int mData)
{
data = mData;
progressbar_V->setValue(data);
}
int progressbarV::getData()
{
return data;
}
void progressbarV::setMinVal(short mMinVal)
{
minVal = mMinVal;
progressbar_V->setMinimum(minVal);
}
short progressbarV::getMinVal()
{
return minVal;
}
void progressbarV::setMaxVal(short mMaxVal)
{
maxVal = mMaxVal;
progressbar_V->setMaximum(maxVal);
}
short progressbarV::getMaxVal()
{
return maxVal;
}
QProgressBar *progressbarV::getProgressBarV()
{
return progressbar_V;
}
void progressbarV::keyReleaseEvent(QKeyEvent *event)
{
}
Since I am new to QT, kindly give me solutions in the form of code snippets
Thanks in advance,
Sam
you need to declare keyReleaseEvent as a public SLOT
public slots:
void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;
so that QT can connect to it using the old connection style.

'drv' does not name a type

Been looking for awhile and I cant find an answer. All paths are included. I'm referencing a class in another namespace in the class I'm creating.
I'm getting the following error:
src/app/Application.h:30:9: error: 'drv' does not name a type
Code Below. Any help is appreciated!
Main.cpp
int main(int argc, char** argv) {
app::Application program;
program.run();
return 0;
}
LEDs.h
#ifndef LEDS_H
#define LEDS_H
namespace drv {
class LEDs {
public:
LEDs();
void InitLEDs(void);
void SetLEDs(const uint8_t value);
private:
static const uint8_t NUM_LEDs = 5;
};
}
#endif /* LEDS_H */
Application.h
#ifndef APPLICATION_H
#define APPLICATION_H
namespace app {
enum State {
NORMAL = 0,
ZONE,
PAIRING,
STUCK,
BATT,
OFF
};
class Application {
public:
Application();
void run(void);
void execute_loop(void);
private:
bool IDLE;
State STATE;
drv::LEDs Leds; // LINE 30
};
}
#endif // APPLICATION_H
Application.cpp
#include "stdint.h"
#include "stdbool.h"
#include "../drv/LEDs.h"
#include "Application.h"
namespace app {
Application::Application() {
IDLE = false;
STATE = NORMAL;
}
void Application::run(void) {
Leds.InitLEDs();
while(1)
{
if(IDLE) {
PowerSaveIdle();
}
else {
execute_loop();
}
}
}
void Application::execute_loop(void)
{
}
}
LEDs.cpp
#include <stdint.h>
#include "LEDs.h"
namespace drv {
LEDs::LEDs() {
}
void LEDs::InitLEDs() {
SetLEDs(0xff);
}
void LEDs::SetLEDs(const uint8_t value) {
//Removed for readability
}
}
You're missing an #include ... line in Application.h. At the top of that file (or just after the inclusion guards) add the line
#include "LEDs.h"