//Bullet kinetic energy calculator
//June 09
#include <QObject>
#include <QApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDialog>
#include <math.h>
#include <stdlib.h>
class ke : public QObject
{
Q_OBJECT
public:
void calc_ke();
signals:
void pass_ke(char* ke);
private slots:
void pass_velocity(char *velocity);
//
void pass_mass(const QString &mass);
private:
float fp_mass;
float fp_velocity;
};
void ke::calc_ke()
{
float fp_kinetic_energy;
char kinetic_energy[32];
//double fp_mass = atof (mass);
//double fp_velocity = atof (velocity);
fp_kinetic_energy=fp_mass*(fp_velocity*fp_velocity )/450450.0;
sprintf(kinetic_energy, "%.4f", fp_kinetic_energy);
emit pass_ke(kinetic_energy);
}
void ke:
ass_velocity(char* velocity)
{
float fp_velocity;
fp_velocity =(float) atof (velocity);
ke::calc_ke();
}
//void ke:
ass_mass(char* mass)
void ke:
ass_mass(const QString &mass)
{
float fp_mass;
fp_mass =(float) atof ((char)mass);
ke::calc_ke();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel* mass_label = new QLabel(QObject::tr("Enter mass in grains"));
QLineEdit* mass_lineEdit = new QLineEdit;
mass_label->setBuddy(mass_lineEdit);
QLabel* velocity_label = new QLabel(QObject::tr("Enter velocity in feet/sec"));
QLineEdit* velocity_lineEdit = new QLineEdit;
velocity_label->setBuddy(velocity_lineEdit);
QLabel* ke_label = new QLabel(0);
QWidget *window = new QWidget;
window->setWindowTitle("Bullet Velocity Calculator");
QObject::connect( mass_lineEdit, SIGNAL(textChanged(const QString &)), &ke, SLOT(pass_mass(const QString &)) );
QObject::connect(velocity_lineEdit, SIGNAL(textChanged(const QString &)), &ke, SLOT(pass_velocity(const QString &)));
QObject::connect(&ke, SIGNAL(pass_ke(const QString &)), ke_label, SLOT(setText(const QString &)));
//TEST CODE
QObject::connect( mass_lineEdit, SIGNAL(textChanged(const QString &)), ke_label, SLOT(setText(const QString &)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mass_lineEdit);
layout->addWidget(velocity_lineEdit);
window->setLayout(layout);
window->show();
return app.exec();
}
Bookmarks