line.cpp file:
#include "line.h"
#include "ui_line.h"
#include<QMessageBox>
#include<QtGui>
#include<QApplication>
#include<QtGui/QLabel>
#include<QPlainTextEdit>
#include<QString>
#include<QLineEdit>
#include<iostream>
#include "math.h"
line::line(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::line)
{
ui->setupUi(this);
connect(this>ui>pushButton,SIGNAL(clicked()),this,SLOT(display1())); //display() connect
connect(this>ui>pushButton_2,SIGNAL(clicked()),this,SLOT(clear())); //clear() connect
}
line::~line() //Destructor
{
delete ui;
}
void line::display1() //Display Function
{
x1=ui->textEdit->toPlainText().toInt();
y1=ui->textEdit_2->toPlainText().toInt();
x2=ui->textEdit_3->toPlainText().toInt();
y2=ui->textEdit_4->toPlainText().toInt();
int dx=abs(x1-x2);
int dy=abs(y1-y2);
display(dx,dy);
int g=0;
display(dx,dy,g);
}
void line::display(int dx,int dy) //Display Overloading
{
QImage img(291,231,QImage::Format_ARGB32);
QRgb rgb=qRgb(255,255,255);
img.fill(QColor(Qt::black).rgb());
int n;
float x_1,y_1;
float x,y;
if(dx>dy)
n=dx;
else
n=dy;
x_1=(float)dx/n;
y_1=(float)dy/n;
img.setPixel(x1,y1,rgb);
x=x1;
y=y1;
ui->label->setPixmap(QPixmap::fromImage(img));
for(int i=0;i<n;i++)
{
x=x+x_1;
y=y+y_1;
img.setPixel(x,y,rgb);
ui->label->setPixmap(QPixmap::fromImage(img));
}
}
void line::display(int dx,int dy,int g) //Display Overloading
{
int x_1,y_1,n;
x_1=x1;
y_1=y1;
this->ui->label_2->clear();
QImage img(281,221,QImage::Format_ARGB32);
QRgb rgb=qRgb(255,255,255);
img.fill(QColor(Qt::black).rgb());
if(abs(dx)>=abs(dy))
{
g=((2*dy)-dx);
n=abs(dx);
while(n>=0)
{
if(g>=0)
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
x_1=x_1+1;
y_1=y_1+1;
g=g+2*(dy-dx);
}
else
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
x_1=x_1+1;
g=g+2*dy;
}
n=n-1;
}
}
else
{
g=((2*dx)-dy);
n=dy;
while(n>=0)
{
if(g>=0)
{
x_1=x_1+1;
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
y_1=y_1+1;
g=g+(2*(dx-dy));
}
else
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
y_1=y_1+1;
g=g+(2*dx);
}
n=n-1;
}
}
}
void line::clear() //clear function
{
ui->textEdit->setText("");
ui->textEdit_2->setText("");
ui->textEdit_3->setText("");
ui->textEdit_4->setText("");
ui->label->clear();
ui->label_2->clear();
}
----------------------------------------------------------------------------------------------------------------------------------
line.h file:
#ifndef LINE_H
#define LINE_H
#include <QMainWindow>
namespace Ui {
class line;
}
class line : public QMainWindow
{
Q_OBJECT
int x1,y1,x2,y2;
public:
explicit line(QWidget *parent = 0);
~line();
private:
Ui::line *ui;
private slots:
void display1(); /*
void display(int,int); Functions
void display(int,int,int);
void clear(); */
};
#endif // LINE_H
#include "line.h"
#include "ui_line.h"
#include<QMessageBox>
#include<QtGui>
#include<QApplication>
#include<QtGui/QLabel>
#include<QPlainTextEdit>
#include<QString>
#include<QLineEdit>
#include<iostream>
#include "math.h"
line::line(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::line)
{
ui->setupUi(this);
connect(this>ui>pushButton,SIGNAL(clicked()),this,SLOT(display1())); //display() connect
connect(this>ui>pushButton_2,SIGNAL(clicked()),this,SLOT(clear())); //clear() connect
}
line::~line() //Destructor
{
delete ui;
}
void line::display1() //Display Function
{
x1=ui->textEdit->toPlainText().toInt();
y1=ui->textEdit_2->toPlainText().toInt();
x2=ui->textEdit_3->toPlainText().toInt();
y2=ui->textEdit_4->toPlainText().toInt();
int dx=abs(x1-x2);
int dy=abs(y1-y2);
display(dx,dy);
int g=0;
display(dx,dy,g);
}
void line::display(int dx,int dy) //Display Overloading
{
QImage img(291,231,QImage::Format_ARGB32);
QRgb rgb=qRgb(255,255,255);
img.fill(QColor(Qt::black).rgb());
int n;
float x_1,y_1;
float x,y;
if(dx>dy)
n=dx;
else
n=dy;
x_1=(float)dx/n;
y_1=(float)dy/n;
img.setPixel(x1,y1,rgb);
x=x1;
y=y1;
ui->label->setPixmap(QPixmap::fromImage(img));
for(int i=0;i<n;i++)
{
x=x+x_1;
y=y+y_1;
img.setPixel(x,y,rgb);
ui->label->setPixmap(QPixmap::fromImage(img));
}
}
void line::display(int dx,int dy,int g) //Display Overloading
{
int x_1,y_1,n;
x_1=x1;
y_1=y1;
this->ui->label_2->clear();
QImage img(281,221,QImage::Format_ARGB32);
QRgb rgb=qRgb(255,255,255);
img.fill(QColor(Qt::black).rgb());
if(abs(dx)>=abs(dy))
{
g=((2*dy)-dx);
n=abs(dx);
while(n>=0)
{
if(g>=0)
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
x_1=x_1+1;
y_1=y_1+1;
g=g+2*(dy-dx);
}
else
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
x_1=x_1+1;
g=g+2*dy;
}
n=n-1;
}
}
else
{
g=((2*dx)-dy);
n=dy;
while(n>=0)
{
if(g>=0)
{
x_1=x_1+1;
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
y_1=y_1+1;
g=g+(2*(dx-dy));
}
else
{
img.setPixel(x_1,y_1,rgb);
ui->label_2->setPixmap(QPixmap::
fromImage(img));
y_1=y_1+1;
g=g+(2*dx);
}
n=n-1;
}
}
}
void line::clear() //clear function
{
ui->textEdit->setText("");
ui->textEdit_2->setText("");
ui->textEdit_3->setText("");
ui->textEdit_4->setText("");
ui->label->clear();
ui->label_2->clear();
}
----------------------------------------------------------------------------------------------------------------------------------
line.h file:
#ifndef LINE_H
#define LINE_H
#include <QMainWindow>
namespace Ui {
class line;
}
class line : public QMainWindow
{
Q_OBJECT
int x1,y1,x2,y2;
public:
explicit line(QWidget *parent = 0);
~line();
private:
Ui::line *ui;
private slots:
void display1(); /*
void display(int,int); Functions
void display(int,int,int);
void clear(); */
};
#endif // LINE_H
Output

there is too many errors in qt editor
ReplyDeleteDid you put the code in the correct files in QT when you made a new project?
DeleteIdeally, a convenience store should be highly visible, easily accessible, and must also have convenient parking options.Stan Store Alternative
ReplyDeleteI enjoy the simplicity of Bolahit Casino, which allows players to focus on gameplay rather than complex menus. situs sabung ayam
ReplyDelete